android - Second spinner not working -


i have problem second spinner not being able select item , save value.

if add s2.setonitemselectedlistener(this); spinner wont select or scroll . if remove listener selection of items enable doesn't catch selection , can tell me missing ?

thanks

    public class menutiendas extends activity implements         onitemselectedlistener{     spinner s1,s2,s3;     string sp1, sp2, sp3 = "";     string id, id_pasajero = "";      @override     protected void oncreate(bundle savedinstancestate) {         // todo auto-generated method stub         super.oncreate(savedinstancestate);         setcontentview(r.layout.menutiendas);         s1 = (spinner)findviewbyid(r.id.spinner1);         s2 = (spinner)findviewbyid(r.id.spinner2);         //s3 = (spinner)findviewbyid(r.id.spinner3);          s1.setonitemselectedlistener(this);         s2.setonitemselectedlistener(this);         //s3.setonitemselectedlistener(this);          sharedpreferences prefs = getsharedpreferences("sea_reg_app", context.mode_private);         id = prefs.getstring("id", "");         id_pasajero = prefs.getstring("id_own","");      }     @override     public void onitemselected(adapterview<?> arg0, view arg1, int arg2,                                long arg3) {         // todo auto-generated method stub         sp1= string.valueof(s1.getselecteditem());         sp2= string.valueof(s2.getselecteditem());         //sp3= string.valueof(s3.getselecteditem());            button siguiente = (button) this.findviewbyid(r.id.button7);         //toast.maketext(this, sp1, toast.length_short).show();           if(sp1.contentequals("superama")) {             list<string> list = new arraylist<string>();             list.add("ace rell de almndrs (fco)");             list.add("ace rell de ajo (fco)");             list.add("ace rell arandanos (fco)");             list.add("ace rell higo (fco)");             list.add("ajo finas hierbas (fco)");              arrayadapter<string> dataadapter = new arrayadapter<string>(this,                     android.r.layout.simple_spinner_item, list);             dataadapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);             dataadapter.notifydatasetchanged();             s2.setadapter(dataadapter);          }           if(sp1.contentequals("city fresko (comer)")) {             list<string> list = new arraylist<string>();             list.add("ace rell almndrs (fco)");             list.add("ace rell ajo (fco)");             list.add("ace rell pimiento rojo (fco)");             list.add("ace rell coco dulce (fco)");             list.add("ace rell arandanos (fco)");             list.add("ace rell datil dulce (fco)");             list.add("ace rell higo (fco)");             list.add("ace rell de pasas dulce (fco)");             list.add("ace rell de pina (fco)");             list.add("ajo finas hierbas (fco)");              arrayadapter<string> dataadapter2 = new arrayadapter<string>(this,                     android.r.layout.simple_spinner_item, list);             dataadapter2.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);             dataadapter2.notifydatasetchanged();             s2.setadapter(dataadapter2);         }         if(sp1.contentequals("city fresko (fresko)")) {             list<string> list = new arraylist<string>();             list.add("ace rell almndrs (fco)");             list.add("ace rell ajo (fco)");             list.add("ace rell pimiento rojo (fco)");             list.add("ace rell coco dulce (fco)");             list.add("ace rell arandanos (fco)");             list.add("ace rell datil dulce (fco)");             list.add("ace rell higo (fco)");             list.add("ace rell pasas dulce (fco)");             list.add("ace rell pina (fco)");             list.add("ajo finas hierbas (fco)");              arrayadapter<string> dataadapter3 = new arrayadapter<string>(this,                     android.r.layout.simple_spinner_item, list);             dataadapter3.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);             dataadapter3.notifydatasetchanged();             s2.setadapter(dataadapter3);         }         if(sp1.contentequals("city fresko (c.market)")) {             list<string> list = new arraylist<string>();             list.add("ace rell almndrs (fco)");             list.add("ace rell ajo (fco)");             list.add("ace rell pimiento rojo (fco)");             list.add("ace rell coco dulce (fco)");             list.add("ace rell arandanos (fco)");             list.add("ace rell de datil dulce (fco)");             list.add("ace rell higo (fco)");             list.add("ace rell pasas dulce (fco)");             list.add("ace rell pina (fco)");             list.add("ajo finas hierbas (fco)");              arrayadapter<string> dataadapter4 = new arrayadapter<string>(this,                     android.r.layout.simple_spinner_item, list);             dataadapter4.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);             dataadapter4.notifydatasetchanged();             s2.setadapter(dataadapter4);         }         if(sp1.contentequals("city fresko (sumesa)")) {             list<string> list = new arraylist<string>();             list.add("ace rell almndrs (fco)");             list.add("ace rell ajo (fco)");             list.add("ace rell pimiento rojo (fco)");             list.add("ace rell coco dulce (fco)");             list.add("ace rell arandanos (fco)");             list.add("ace rell datil dulce (fco)");             list.add("ace rell. higo (fco)");             list.add("ace rell pasas dulce (fco)");             list.add("ace rell pina (fco)");             list.add("ajo finas hierbas (fco)");              arrayadapter<string> dataadapter5 = new arrayadapter<string>(this,                     android.r.layout.simple_spinner_item, list);             dataadapter5.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);             dataadapter5.notifydatasetchanged();             s2.setadapter(dataadapter5);         }         if(sp1.contentequals("chedraui")) {             list<string> list = new arraylist<string>();             list.add("ace rell almendras (fco)");             list.add("ace rell coco dulce (fco)");             list.add("ace rell higo (fco)");             list.add("ace rell pasas dulce (fco)");             list.add("ajo finas hierbas (fco)");              arrayadapter<string> dataadapter6 = new arrayadapter<string>(this,                     android.r.layout.simple_spinner_item, list);             dataadapter6.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);             dataadapter6.notifydatasetchanged();             s2.setadapter(dataadapter6);          }          siguiente.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                   log.d("log", "resultado sp1 " + sp1);                 log.d("log", "resultado sp2 " + sp2);                  //leemos status de usuario y determinamos donde ir.                 sharedpreferences prefs = getsharedpreferences("sea_reg_app", context.mode_private);                 sharedpreferences.editor editor = prefs.edit();                 editor.putstring("sp1", sp1.tostring());                 editor.putstring("sp2", sp2.tostring());                 //editor.putstring("sp3", sp3.tostring());                 //cbmarcame1_1 = prefs.getboolean("guardar_vincular",false);                 editor.commit();                 startactivity(new intent(menutiendas.this, formulario.class));             }         });     }      @override     public void onnothingselected(adapterview<?> arg0) {         // todo auto-generated method stub      } } 

below xml code of activity

 <?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical" > <textview         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:padding="8dip"         android:text="@string/lblacc"         android:layout_margintop="30dp"/> <spinner     android:id="@+id/spinner1"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:layout_marginleft="8dip"     android:layout_marginright="8dip"     android:layout_margintop="20dp"     android:entries="@array/tienda" /> <textview     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:padding="8dip"     android:text="@string/lblsubacc1"     android:layout_margintop="20dp" /> <spinner     android:id="@+id/spinner2"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:layout_margintop="20dp"     android:layout_marginleft="8dip"     android:layout_marginright="8dip"     /> <button     android:text="siguiente"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:id="@+id/button7"     android:layout_margintop="20dp"/> </linearlayout> 

you have check id, firing inside onitemselected listener make work.

@override public void onitemselected(adapterview<?> arg0, view arg1, int arg2,                            long arg3) {     // todo auto-generated method stub      switch (arg0.getid()){         case r.id.spinner1:             sp1= string.valueof(s1.getselecteditem());             if(sp1.contentequals("superama")) {                 list<string> list = new arraylist<string>();                 list.add("ace rell de almndrs (fco)");                 list.add("ace rell de ajo (fco)");                 list.add("ace rell arandanos (fco)");                 list.add("ace rell higo (fco)");                 list.add("ajo finas hierbas (fco)");                  arrayadapter<string> dataadapter = new arrayadapter<string>(this,                         android.r.layout.simple_spinner_item, list);                 dataadapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);                 dataadapter.notifydatasetchanged();                 s2.setadapter(dataadapter);              }               if(sp1.contentequals("city fresko (comer)")) {                 list<string> list = new arraylist<string>();                 list.add("ace rell almndrs (fco)");                 list.add("ace rell ajo (fco)");                 list.add("ace rell pimiento rojo (fco)");                 list.add("ace rell coco dulce (fco)");                 list.add("ace rell arandanos (fco)");                 list.add("ace rell datil dulce (fco)");                 list.add("ace rell higo (fco)");                 list.add("ace rell de pasas dulce (fco)");                 list.add("ace rell de pina (fco)");                 list.add("ajo finas hierbas (fco)");                  arrayadapter<string> dataadapter2 = new arrayadapter<string>(this,                         android.r.layout.simple_spinner_item, list);                 dataadapter2.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);                 dataadapter2.notifydatasetchanged();                 s2.setadapter(dataadapter2);             }             if(sp1.contentequals("city fresko (fresko)")) {                 list<string> list = new arraylist<string>();                 list.add("ace rell almndrs (fco)");                 list.add("ace rell ajo (fco)");                 list.add("ace rell pimiento rojo (fco)");                 list.add("ace rell coco dulce (fco)");                 list.add("ace rell arandanos (fco)");                 list.add("ace rell datil dulce (fco)");                 list.add("ace rell higo (fco)");                 list.add("ace rell pasas dulce (fco)");                 list.add("ace rell pina (fco)");                 list.add("ajo finas hierbas (fco)");                  arrayadapter<string> dataadapter3 = new arrayadapter<string>(this,                         android.r.layout.simple_spinner_item, list);                 dataadapter3.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);                 dataadapter3.notifydatasetchanged();                 s2.setadapter(dataadapter3);             }             if(sp1.contentequals("city fresko (c.market)")) {                 list<string> list = new arraylist<string>();                 list.add("ace rell almndrs (fco)");                 list.add("ace rell ajo (fco)");                 list.add("ace rell pimiento rojo (fco)");                 list.add("ace rell coco dulce (fco)");                 list.add("ace rell arandanos (fco)");                 list.add("ace rell de datil dulce (fco)");                 list.add("ace rell higo (fco)");                 list.add("ace rell pasas dulce (fco)");                 list.add("ace rell pina (fco)");                 list.add("ajo finas hierbas (fco)");                  arrayadapter<string> dataadapter4 = new arrayadapter<string>(this,                         android.r.layout.simple_spinner_item, list);                 dataadapter4.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);                 dataadapter4.notifydatasetchanged();                 s2.setadapter(dataadapter4);             }             if(sp1.contentequals("city fresko (sumesa)")) {                 list<string> list = new arraylist<string>();                 list.add("ace rell almndrs (fco)");                 list.add("ace rell ajo (fco)");                 list.add("ace rell pimiento rojo (fco)");                 list.add("ace rell coco dulce (fco)");                 list.add("ace rell arandanos (fco)");                 list.add("ace rell datil dulce (fco)");                 list.add("ace rell. higo (fco)");                 list.add("ace rell pasas dulce (fco)");                 list.add("ace rell pina (fco)");                 list.add("ajo finas hierbas (fco)");                  arrayadapter<string> dataadapter5 = new arrayadapter<string>(this,                         android.r.layout.simple_spinner_item, list);                 dataadapter5.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);                 dataadapter5.notifydatasetchanged();                 s2.setadapter(dataadapter5);             }             if(sp1.contentequals("chedraui")) {                 list<string> list = new arraylist<string>();                 list.add("ace rell almendras (fco)");                 list.add("ace rell coco dulce (fco)");                 list.add("ace rell higo (fco)");                 list.add("ace rell pasas dulce (fco)");                 list.add("ajo finas hierbas (fco)");                  arrayadapter<string> dataadapter6 = new arrayadapter<string>(this,                         android.r.layout.simple_spinner_item, list);                 dataadapter6.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);                 dataadapter6.notifydatasetchanged();                 s2.setadapter(dataadapter6);              }              break;          case r.id.spinner2:             sp2= string.valueof(s2.getselecteditem());             break;     }         button siguiente = (button) this.findviewbyid(r.id.button7);      siguiente.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {               log.d("log", "resultado sp1 " + sp1);             log.d("log", "resultado sp2 " + sp2);              //leemos status de usuario y determinamos donde ir.             sharedpreferences prefs = getsharedpreferences("sea_reg_app", context.mode_private);             sharedpreferences.editor editor = prefs.edit();             editor.putstring("sp1", sp1.tostring());             editor.putstring("sp2", sp2.tostring());             //editor.putstring("sp3", sp3.tostring());             //cbmarcame1_1 = prefs.getboolean("guardar_vincular",false);             editor.commit();            // startactivity(new intent(this, formulario.class));         }     }); } 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -