Populate android spinner dynamically -


i have created textview in android code below:

txtv = new textview(this); txtv.settext("text"); ll.addview(txtv);  

same way have created spinner:

spinner = new spinner(this); ll.addview(spinner); 

but unable populate value on spinner. tutorials giving populating spinner arrayadapter taking id of xml, r.id..... since creating dynamic, can't way. how can populate spinner dynamically?

you need layout

view linearlayout =  findviewbyid(r.id.layoutid); cerate spinner     spinner spinner = new spinner(this); //make sure have valid layout parameters. spinner .setlayoutparams(new     layoutparams(layoutparams.fill_parent,layoutparams.wrap_content));                  arrayadapter spinnerarrayadapter = new arrayadapter(this,                         android.r.layout.simple_spinner_dropdown_item, spinnerlist);                 spinner.setadapter(spinnerarrayadapter); add spinner view  ((linearlayout) linearlayout).addview(spinner ); 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -