我有一个ScrollView,我想插入一个用户指定数量的HorizontalScrollViews。因此,用户说他想拥有一个5x5元素的矩阵,我想插入5个HorizontalScrollViews,每个对象具有5个EditText对象。我的程序按照预期的那样添加了第一行,而其余的则没有。
for (int i = 0; i < number; i++) {
LinearLayout ll = new LinearLayout(this);
ll.setLayoutParams(par2);
HorizontalScrollView row = new HorizontalScrollView(this);
row.setLayoutParams(par1);
row.addView(ll);
for (int j = 0; j < number; j++) {
EditText txt = new EditText(this);
txt.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
txt.setHint(i+","+j);
ll.addView(txt);
}
latout_in_scrollview.addView(row);
}
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?谢谢!
编辑:使用的1:1代码
LinearLayout dijkstra_rows;
FrameLayout.LayoutParams par1 = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams par2 = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_dijkstra);
dijkstra_rows = (LinearLayout) findViewById(R.id.dijkstra_rows);
Bundle extras = getIntent().getExtras();
number …Run Code Online (Sandbox Code Playgroud) 我们有基于Web的表单登录身份验证和j_securtiy_check工作.我们想通过程序化登录身份验证来更改它.让servlet验证传递给它的用户名和密码的正确方法是什么?servlet显然没有受到保护.
我们一直在试验这个server.xml Realm:
<Realm className="org.apache.catalina.realm.DataSourceRealm"
dataSourceName="UserDatabase"
userTable="app_user" userNameCol="login_name" userCredCol="password_value"
userRoleTable="user_perm" roleNameCol="permission_name"
allRolesMode="authOnly" digest="MD5"
/>
Run Code Online (Sandbox Code Playgroud)
原因是我们有一个java webstart客户端,它将登录信息发送到不受保护的loginServlet.此servlet当前针对JOSSO单点登录服务进行身份验证,但我希望将其删除并对初学者使用简单的tomcat7身份验证.然后最终迁移到OpenAM.如果我可以以编程方式生成JSSESSIONIDSSO值并将其填充到cookie中.
这是我发现的一些代码.这是调用身份验证的正确方法吗?
ApplicationContextFacade acf = (ApplicationContextFacade) this.getServletContext();
Field privateField = ApplicationContextFacade.class.getDeclaredField("context");
privateField.setAccessible(true);
ApplicationContext appContext = (ApplicationContext) privateField.get(acf);
Field privateField2 = ApplicationContext.class.getDeclaredField("context");
privateField2.setAccessible(true);
StandardContext stdContext = (StandardContext) privateField2.get(appContext);
Realm realm = stdContext.getRealm();
Principal principal = realm.authenticate(loginBean.getUsername(), loginBean.getPassword());
if (principal == null)
{
return 0;
}
GenericPrincipal genericPrincipal = (GenericPrincipal) principal;
System.out.println ("genericPrincipal=" + genericPrincipal.toString());
Run Code Online (Sandbox Code Playgroud) authentication tomcat servlets j-security-check programmatically-created
标题说明了一切,希望如此.
1)我以编程方式创建一个View:
RelativeLayout rl = new RelativeLayout(this);
Run Code Online (Sandbox Code Playgroud)
2)我想将它添加到现有的LinearLayout,之后我想将一个Style添加到RelativeLayout.就像是:
LinearLayout ll = (LinearLayout) findViewById(R.id.MyLinearLayout);
RelativeLayout rl = new RelativeLayout(this);
ll.addView(rl);
//add Style to rl here
Run Code Online (Sandbox Code Playgroud)
我找不到办法做到这一点!
我知道有办法以编程方式添加Style.就像是:
RelativeLayout rl = new RelativeLayout(this, null, R.style.MyRelativeLayout);
Run Code Online (Sandbox Code Playgroud)
但是在我将relativelayout添加到linearlayout之前,这将添加样式.因此,relativelayout不是"打印"的,因为在我将其添加到linearlayout之前,他应该如何知道linearlayout是他的父级.
在创建此视图并将其添加到父视图后,是否有人有办法以编程方式将样式添加到视图?
希望你明白我的意思.
我有一个视图,我动态加载按钮.所以我有一个for循环遍历所有按钮.由于这是动态的,我想以编程方式创建自动布局.现在我有以下代码:
for var i = 0; i < data.count; i++ {
let button = UIButton.buttonWithType(UIButtonType.System) as! UIButton
button.backgroundColor = UIColor.greenColor()
button.setTitle("Button", forState: UIControlState.Normal)
button.setTranslatesAutoresizingMaskIntoConstraints(false)
self.view.addSubview(button)
let centerXConstraint = NSLayoutConstraint(item: button, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: scrollView, attribute: NSLayoutAttribute.CenterX, multiplier: 1.0, constant: 0)
let centerYConstraint = NSLayoutConstraint(item: button, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: scrollView, attribute: NSLayoutAttribute.Top, multiplier: 1.0, constant:15)
let widthConstraint = NSLayoutConstraint(item: button, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: 200)
let heightConstraint = NSLayoutConstraint(item: button, …Run Code Online (Sandbox Code Playgroud) 我一直在研究这个问题但是找不到我需要的东西.我想学习如何以编程方式使用子视图控制器创建容器视图.我仍然相当新,并且学习基础知识,但是从我收集的内容来看,过去常常使用可恢复的视图并在将容器视图对象添加到库之前将它们附加到子视图控制器(对吗?),我正在寻找一个教程或示例代码,显示如何从头开始,使用xib,但没有任何复杂性,如添加表格单元格等...只是容器和子程序.那有意义吗?我相信一定有什么东西谢谢你,如果你能提供帮助的话.
更新------------------------------------------------- -------------------------------------------------- -------------------我设法创建了一个带有UIButton动作的子视图控制器.相关代码:
- (IBAction)Pressed:(id)sender {
ChildViewController *childViewController = [[ChildViewController alloc]init];
[self displayContentController:childViewController];
}
- (void) displayContentController: (UIViewController*) content {
[self addChildViewController:content];
content.view.frame = CGRectMake(0, 115, 320, 240);
content.view.backgroundColor = [UIColor redColor];
CATransition *transition = [CATransition animation];
transition.duration = 1;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[content.view.layer addAnimation:transition forKey:nil];
[self.view addSubview:content.view];
[content didMoveToParentViewController:self];
}
Run Code Online (Sandbox Code Playgroud)
所以这很好.我点击按钮和一个红色正方形,子视图控制器,占据屏幕的一小部分出现.我想知道的是,这是最佳做法.
objective-c childviewcontroller uicontainerview programmatically-created
我想添加一个按钮作为根视图的子视图.按钮必须水平放置在中心以及垂直于superview的中心.我以编程方式使用NSLayoutConstraints.这是我的代码.
import UIKit
class ViewController: UIViewController {
var button : UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func motionEnded(motion: UIEventSubtype, withEvent event: UIEvent?) {
button = UIButton()
button.setTitle("Hello World", forState: .Normal)
button.backgroundColor = UIColor.blueColor()
button.sizeToFit()
self.view.addSubview(button)
NSLayoutConstraint.activateConstraints([
NSLayoutConstraint(item: button, attribute: .CenterX, relatedBy: .Equal, toItem: self.view, attribute: .CenterX, multiplier: 1, constant: 0), …Run Code Online (Sandbox Code Playgroud) 我正在使用tinyMCE 4.x,并希望以编程方式删除整个编辑器文本中的任何设置格式。它应该执行removeFormat 命令的操作。到目前为止我来了:
tinymce.execCommand('selectAll', true, 'texteditor');
tinymce.execCommand('RemoveFormat', true, 'texteditor');
Run Code Online (Sandbox Code Playgroud)
removeFormat 仅适用于预先选定的文本,因此我在RemoveFormat 之前执行“SelectAll”。这工作正常,但在删除格式后所有内容都保持选中状态。所以问题是:有没有一种方法可以删除任何格式而不选择之前的所有格式?如果否,如何取消选择之前选择的文本?(之后我尝试将焦点集中在文本编辑器上,但选择仍然存在)。我确信有一个简单的方法只是在网上找不到它。
关于这个主题有很多有趣的帖子,但我似乎要么不理解他们的答案,要么目标不同。这就是我正在尝试做的事情。我有两个(或更多)函数想要组合成一个新函数。以下片段显示了我的开始内容以及我想要的结束内容。
def a(x):
0.2 * x[1] - 0.4 * x[0]
def b(x):
0.4 * x[0] - 0.2 * x[1]
def ab(x):
return [0.2 * x[1] - 0.4 * x[0], 0.4 * x[0] - 0.2 * x[1]]
Run Code Online (Sandbox Code Playgroud)
问题是,我想ab在运行时动态创建。我有一个包含所有函数的列表ml,因此我可以在新函数中执行以下操作
def abl(x):
ml = [a, b]
rl = []
i = 0
for f in ml:
rl.append(f(x[i]))
i = i + 1
Run Code Online (Sandbox Code Playgroud)
然后打电话abl。该代码组合了各个函数并产生预期的输出。然而,每次调用都abl rl必须重新构建,这似乎很浪费。
是否有另一种方法可以组合a和b来创建新函数ab?
我正在开发一款涉及很多表格的iPhone应用程序.目前我为每个设置页面都有一个ViewController类,其中有一个UITableView加载了可能的设置.当有人点击某个设置时,他们会被带到新视图以输入表单值,或者允许他们输入适当的内容.
保持干燥的最佳方法是什么?这个实现的哪些部分可以实现一次并重新使用?
当有人点击进入新视图的设置选项时,如何创建此视图并根据代码中的数据类型(uitextfield或picker或其他内容)添加文本字段?
这是我设置委托的第一个VC:
class DiscoverVC: UIViewController, SetLocationDelegate {
var name = ""
let loc = LocationVC()
override func viewDidLoad() {
super.viewDidLoad()
self.loc.delegate = self
}
func getLocation(loc: String) {
self.name = loc
self.tableView.reloadData()
}
}
Run Code Online (Sandbox Code Playgroud)
这是第二个视图控制器,我从那里通过委托获取数据:
protocol SetLocationDelegate: class {
func getLocation(loc: String)
}
class LocationVC: UIViewController {
weak var delegate: SetLocationDelegate?
override func viewDidLoad() {
super.viewDidLoad()
self.delegate?.getLocation(loc: "Sam")
}
}
Run Code Online (Sandbox Code Playgroud)
每当我尝试传递数据时,它都不会调用该方法,并且委托也不会被调用。急需帮助。
android ×2
ios ×2
objective-c ×2
swift ×2
autolayout ×1
combinations ×1
delegates ×1
function ×1
iphone ×1
python ×1
scrollview ×1
servlets ×1
styles ×1
tinymce-4 ×1
tomcat ×1
unselect ×1
view ×1