java - How to add two Buttons to LinearLayout programmatically? -
i can't addview() 2 times. in fact, want 1 textview(left) , 1 button(right) besides. how can position them in linearlayout?
if (success == 1) { content = json.getjsonarray(tag_comments); layoutvertical.removeallviews(); final int n = content.length(); final button[] mybutton = new button[n]; final linearlayout[] mylayout = new linearlayout[n]; final textview[] mytextview = new textview[n]; (int = 0; < content.length(); i++) { jsonobject c = content.getjsonobject(i); string name = c.getstring(tag_content); final linearlayout layouthorizontal = new linearlayout( getactivity()); layouthorizontal .setorientation(linearlayout.horizontal); layouthorizontal.setid(i); layouthorizontal.setbackground(getresources() .getdrawable(r.drawable.borderadmincomment)); final textview rowtextview = (textview) new textview( getactivity()); rowtextview.settext(name); rowtextview.setid(i); final button rowbutton = new button(getactivity()); rowbutton.setlayoutparams(new layoutparams(1, layoutparams.match_parent)); rowbutton.setid(i); rowbutton.setbackgroundresource(r.drawable.croix); rowbutton .setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { } }); layouthorizontal.addview(rowtextview, 0); layouthorizontal.addview(rowbutton, 1); rowtextview.setwidth(400); //rowtextview.setheight(150); //rowbutton.setheight(150); layoutvertical.addview(layouthorizontal); mybutton[i] = rowbutton; mylayout[i] = layouthorizontal; mytextview[i] = rowtextview; } } it's not works.
thank you.
you forgot set layout params horizontal layout , rowtextview.
for example:
layouthorizontal.setlayoutparams(new layoutparams(layoutparams.fill_parent,layoutparams.wrap_content)); java android android-linearlayout
No comments:
Post a Comment