android - to update the second autocompletetextview based on the value of the first one -


in android app have autocompletetextview feild suggest different state names user. code follows:

 arrayadapter<string> state_adapter=new arrayadapter<string>(this, android.r.layout.select_dialog_item,state);     actv_state=(autocompletetextview)findviewbyid(r.id.edt_state);     actv_state.setthreshold(1);     actv_state.setadapter(state_adapter); 

then take value of state in string using textwatcher in way:

 textwatcher state_text=new textwatcher() {      @override     public void ontextchanged(charsequence s, int start, int before, int count) {         // todo auto-generated method stub         str_state=actv_state.gettext().tostring();     }      @override     public void beforetextchanged(charsequence s, int start, int count,             int after) {         // todo auto-generated method stub      }      @override     public void aftertextchanged(editable s) {         // todo auto-generated method stub      } }; actv_state.addtextchangedlistener(state_text);  

after trying display city names in autocompletetextview based on state selected.. cant seem figure out put code show city names based on state selected????

 if(str_state.equalsignorecase("madhya pradesh"))          {           arrayadapter<string> mp_city_adapter=new arrayadapter<string>(this, android.r.layout.select_dialog_item,mp_city);           actv_city=(autocompletetextview)findviewbyid(r.id.app_city);           actv_city.setthreshold(1);           actv_city.setadapter(mp_city_adapter);          }           if(str_state.equalsignorecase("chattisgarh"))          {           arrayadapter<string> mp_city_adapter=new arrayadapter<string>(this, android.r.layout.select_dialog_item,mp_city);           actv_city=(autocompletetextview)findviewbyid(r.id.app_city);           actv_city.setthreshold(1);           actv_city.setadapter(mp_city_adapter);          } 

how go that?? cant seem figure out ! please if knows solution this!! thanks!

it should inside autocomplete textview itemclick listener

 actv_state.setonitemclicklistener(new onitemclicklistener(){          @override         public void onitemclick(adapterview<?> parent, view view, int position, long rowid) {           if(actv_state.gettext().tostring().equals("madhya pradesh"))      {       arrayadapter<string> mp_city_adapter=new arrayadapter<string>(this, android.r.layout.select_dialog_item,mp_city);       actv_city=(autocompletetextview)findviewbyid(r.id.app_city);       actv_city.setthreshold(1);       actv_city.setadapter(mp_city_adapter);      }       if(actv_state.gettext().tostring().equals("chattisgarh"))      {       arrayadapter<string> mp_city_adapter=new arrayadapter<string>(this, android.r.layout.select_dialog_item,mp_city);       actv_city=(autocompletetextview)findviewbyid(r.id.app_city);       actv_city.setthreshold(1);       actv_city.setadapter(mp_city_adapter);      }          }     }); 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -