How to know selected spinner id in android creating programmatically -


i have 6 spinners , create dynamically.

list<spinner>listspinner        = new arraylist<spinner>(); spinner sp; for(int i;0;i<6; i++) {    sp= new spinner(this);    sp.setid(i); // load data on spinner   listspinner.add(sp);   } 

now concern is, how know particular id of clicked spinner.

if click third spinner how of spinner. try this:

sp.setonitemselectedlistener(new onitemselectedlistener() {                              @override                             public void onitemselected(adapterview<?> parent, view view1, int pos, long id) {                                  (int d = 0; d < listspinner.size(); d++){                                      if (listspinner.get(d).getid()==(id)){ // not clear id                                          spinnerstring =listspinner.get(d).getselecteditem().tostring();                                         log.i("spinn", "selected spinner value=" + spinnerstring );                                       }                                     }                                 return;                               }                             @override                             public void onnothingselected(adapterview<?> arg0) {                              }                         }); 

but id of spinner, not spinner items.

do :

for (int d = 0; d < listspinner.size(); d++) {    spinner s = (spinner)findviewbyid(listspinner.get(d));    log.i("spinn", "selected spinner value=" + s.getselecteditem().tostring() ); } 

the point is, need call findviewbyid, using id in listspinner before getting selected item.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -