xml - How to customize a dynamic, programmatic layout - Android -
i dealing sample code using create app pulls in surveys server. layout rendering done in java rather in xml , having problem having labels , text editing boxes (for questions , answers, respectively) squishing eachother on same line rather sitting 1 on top of other on seperate lines default rendering in xml.
i want have labels above text edit boxes both can stretch across screen , seen better.
the code overall layout here:
private boolean displayform() { try { scrollview sv = new scrollview(this); //need tablelayout here! final linearlayout ll = new linearlayout(this); sv.addview(ll); ll.setorientation(android.widget.linearlayout.vertical); ll.setbackgroundresource(r.color.background); int i; (i=0;i<theform.fields.size();i++) { if (theform.fields.elementat(i).gettype().equals("text")) { theform.fields.elementat(i).obj = new editsurvey(this,(theform.fields.elementat(i).isrequired() ? "*" : "") + theform.fields.elementat(i).getlabel(),""); ll.addview((view) theform.fields.elementat(i).obj); } if (theform.fields.elementat(i).gettype().equals("numeric")) { theform.fields.elementat(i).obj = new editsurvey(this,(theform.fields.elementat(i).isrequired() ? "*" : "") + theform.fields.elementat(i).getlabel(),""); ((editsurvey)theform.fields.elementat(i).obj).makenumeric(); ll.addview((view) theform.fields.elementat(i).obj); } if (theform.fields.elementat(i).gettype().equals("choice")) { theform.fields.elementat(i).obj = new surveyspinners(this,(theform.fields.elementat(i).isrequired() ? "*" : "") + theform.fields.elementat(i).getlabel(),theform.fields.elementat(i).getoptions()); ll.addview((view) theform.fields.elementat(i).obj); } }
the code pulling in labels , text editing boxes here:
public class editsurvey extends linearlayout { textview label; edittext txtbox; public editsurvey(context context,string labeltext,string initialtext) { super(context); label = new textview(context); label.settext(labeltext); label.settextcolor(0xff000000); //label.setlayoutparams(new layoutparams(viewgroup.layoutparams.fill_parent,viewgroup.layoutparams.wrap_content)); txtbox = new edittext(context); txtbox.settext(initialtext); //txtbox.setlayoutparams(new layoutparams(viewgroup.layoutparams.fill_parent,viewgroup.layoutparams.wrap_content)); this.addview(label); this.addview(txtbox); }
i've left out other code snippet pulls in labels spinners, pretty same.
this not code, clear (it's frank abelson's), trying wrangle purposes.
any fantastic.
Comments
Post a Comment