android dynamic generate edittext and use its values -
my app. has button if it's presses 2 edittext fields apear , , if it's pressed again 2 other edittext fields apear , on. want save data in fields in arraylist (or structure) sample of code 1- edittext field apears:
<edittext xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:minheight="50dp" , mainacvtivity code :
linearlayout llayout; arraylist<string> marray = new arraylist<string>(); int numberofboxes = 2; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); final layoutinflater inflater = (layoutinflater)getsystemservice(context.layout_inflater_service); llayout = (linearlayout)findviewbyid(r.id.layout1); final edittext addedudate = (edittext)inflater.inflate(r.layout.text, null); final edittext addeduinfo = (edittext)inflater.inflate(r.layout.text, null); button b2 = (button)findviewbyid(r.id.button2); button b = (button)findviewbyid(r.id.button1); b.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if (llayout.getchildat(numberofboxes) == null) { llayout.addview(addedudate); llayout.addview(addeduinfo); numberofboxes += 2; } } });
if understand problem properly, simple
arraylist<string> list=new arraylist<string>(); list.add(addedudate.gettext().tostring()); should work.
Comments
Post a Comment