create EditText view row in Android -
i've managed add edittext(s) dynamically , retrieve values in android, , got program code here (sample below)
public class sample extends activity { private list<edittext> edittextlist = new arraylist<edittext>(); @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); linearlayout linearlayout = new linearlayout(this); viewgroup.layoutparams params = new viewgroup.layoutparams(fill_parent, wrap_content); linearlayout.setlayoutparams(params); linearlayout.setorientation(vertical); int count = 10; linearlayout.addview(tablelayout(count)); linearlayout.addview(submitbutton()); setcontentview(linearlayout); } private button submitbutton() { button button = new button(this); button.setheight(wrap_content); button.settext("submit"); button.setonclicklistener(submitlistener); return button; } // access value of edittext private view.onclicklistener submitlistener = new view.onclicklistener() { public void onclick(view view) { stringbuilder stringbuilder = new stringbuilder(); (edittext edittext : edittextlist) { stringbuilder.append(edittext.gettext().tostring()); } } }; // using tablelayout provides neat ordering structure private tablelayout tablelayout(int count) { tablelayout tablelayout = new tablelayout(this); tablelayout.setstretchallcolumns(true); int noofrows = count / 5; (int = 0; < noofrows; i++) { int rowid = 5 * i; tablelayout.addview(createonefullrow(rowid)); } int individualcells = count % 5; tablelayout.addview(createleftovercells(individualcells, count)); return tablelayout; } private tablerow createleftovercells(int individualcells, int count) { tablerow tablerow = new tablerow(this); tablerow.setpadding(0, 10, 0, 0); int rowid = count - individualcells; (int = 1; <= individualcells; i++) { tablerow.addview(edittext(string.valueof(rowid + i))); } return tablerow; } private tablerow createonefullrow(int rowid) { tablerow tablerow = new tablerow(this); tablerow.setpadding(0, 10, 0, 0); (int = 1; <= 5; i++) { tablerow.addview(edittext(string.valueof(rowid + i))); } return tablerow; } } this output printscreen 
how can make edittext view shown picture below? 
linearlayout main,clild; main = new linearlayout(....); // vertical orientation main.setorientation(linearlayout.vertical); for(int i=0;i<5;i++) { child = new linearlayout(...); // horizontal orientation child.setorientation(linearlayout.horizontal); for(int j=0;j<i;j++) { edittext ed = new edittext(...); child.addview(ed); } main.addview(child); }
Comments
Post a Comment