Change layout using a spinner in Android -


i'm trying change layout of activity according selection inside spinner. after first selection, spinner become white , i'm not able decide selection. code i'm using following:

public class mainactivity extends activity implements onitemselectedlistener {  spinner spinner; string[] options = { "modulo1", "modulo2" };  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      spinner = (spinner) findviewbyid(r.id.spinner);     arrayadapter<string> adapter_state = new arrayadapter<string>(this,             android.r.layout.simple_spinner_item, options);     adapter_state             .setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);     spinner.setadapter(adapter_state);     spinner.setonitemselectedlistener(this);  }  int check = 0;  public void onitemselected(adapterview<?> parent, view view, int position,         long id) {     check = check + 1;     if (check > 1) {         int selstate = spinner.getselecteditemposition();         switch (selstate) {         case 0:             setcontentview(r.layout.activity_main);              break;         case 1:             setcontentview(r.layout.activity2_main);              break;          }      } }  @override public void onnothingselected(adapterview<?> arg0) {     // todo auto-generated method stub  }  // @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.main, menu);     return true; } 

}

any suggestion? thanks

the spinner referring in first activity. after have replaced content, spinner isn't there anymore. if have spinner in second layout, have reconnect , set listener again. have run oncreate stuff after every setcontentview...

as side note, whatever trying do, not way go. show full layout, better use activity.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -