Dynamically add EditText, Spinner, Radiobutton in Android -
need add edittext, spinner , radiobutton based on array length.
gquestionedittext = (edittext) findviewbyid(r.id.questioneditext); gquestionspinner = (spinner) findviewbyid(r.id.spinnerquestion); gquestionradiobutton = (radiobutton) findviewbyid(r.id.questionradiobutton); (int = 0; < subslotid.size(); i++) { }
based on array size need add edittext,spinner , radio button, please suggest me add, , how differentiate id's , values.
thanks
try below code add dynamic views edittext, textview, spinner, radiobutton,.. layout based on size of array. sample code, not tested.
linearlayout ll = new linearlayout(this); edittext edittext = new edittext(this); edittext.setid(edittext.generateviewid()); ll.addview(edittext); spinner dynamicspinner = new spinner(this); options = new arraylist<string>(); options.add("january"); options.add("february"); arrayadapter<string> adapter = new arrayadapter<string>(this,android.r.layout.simple_dropdown_item_1line, options); dynamicspinner.setadapter(adapter); ll.addview(dynamicspinner); radiobutton rdbtn = new radiobutton(this); rdbtn.setid(rdbtn.generateviewid()); rdbtn.settext("radio " + rdbtn.getid()); ll.addview(rdbtn);
edittext.generateviewid()
generate unique id view, can used details of view @ later point of time...
Comments
Post a Comment