Android different selection spinner show different textview -


i spinner show different textview different selections choosen on spinner in android studio. drug interactions application when user chooses drug spinner different interaction appear each one. suggestions useful.

below code,

    public class myactivity extends activity implements onitemselectedlistener {     spinner spinner;     textview showmed;     private string[] state = {"adalimumab",             "etanercept",             "tacrolimus",             "mycophenolic acid",             "bicalutamide",             "darbepoetin alfa",             "ciclosporin",             "interferon beta-1a",             "triptorelin"};      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_my);         system.out.println(state.length);         showmed = (textview) findviewbyid(r.id.showgender);         spinner = (spinner) findviewbyid(r.id.spinner);         arrayadapter<string> adapter_state = new arrayadapter<string>(this,                 android.r.layout.simple_spinner_item, state);         adapter_state                 .setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);         spinner.setadapter(adapter_state);         spinner.setonitemselectedlistener(this);       }      public void onitemselected(adapterview<?> parent, view view, int position,                                long id) {         spinner.setselection(position);         string selstate = (string) spinner.getselecteditem();         showmed.settext("your drug:" + selstate);      }      @override     public void onnothingselected(adapterview<?> arg0) {         // todo auto-generated method stub      } 

i believe approach might been looking for:

public void onitemselected(adapterview<?> parent, view view, int position,                            long id) {                 switch(position) {                 case 0:                showmed.settext("your drug number 0 on list");                 break;                 case 1:                showmed.settext("your drug number 1 on list");                 break;  }    } 

you should update final textview showmed;


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -