Convert Json array to Assosiative array and bind it to AutoCompleteTextView -- Android -


i have array below ..

[{"instituteid":"1","institutename":"demo institute"},{"instituteid":"16","institutename":"sheridan college"},{"instituteid":"17","institutename":"icent prosp"},{"instituteid":"18","institutename":"seneca college"}] 

i want convert array associative , want set institution name autocompletetextview.

here code

    @override     protected void onpostexecute(string res) {          try {              jsonobject responseobject = new jsonobject(res);             string status=responseobject.getstring("status");             jsonarray detailsarray = responseobject.getjsonarray("institutelist");              string[] newarray = new gson().fromjson(string.valueof(detailsarray),string[].class);              log.i("institute register assc" , string.valueof(newarray));              if(status.equals("true")) {    autotextview = (autocompletetextview) findviewbyid(r.id.instname_field);                 arrayadapter<string> arrayadapter = new arrayadapter<string>(this,                         android.r.layout.simple_list_item_1, proglanguages);                 autotextview.setthreshold(1);                 autotextview.setadapter(arrayadapter);                  toast.maketext(getapplicationcontext(), "response successful",                         toast.length_long).show();             }           } catch (jsonexception e) {             e.printstacktrace();         }     } 

here code of autocomplete view in xml file..

   <linearlayout     android:layout_width="match_parent"     android:layout_height="40dp"     android:id="@+id/autocompt"     android:orientation="vertical">      <autocompletetextview         android:id="@+id/instname_field"         android:layout_width="match_parent"         android:hint="type institution name"         android:paddingleft="10dp"         android:textcolor="#fff"         android:background="#b8d1e5"         android:layout_height="40dp"         android:textsize="20dp"         android:ems="10"/>     </linearlayout> 

thanks...

added log

enter image description here

try this, here changes method used getting institution name array. may work you.

    jsonobject responseobject = new jsonobject(res);     string status=responseobject.getstring("status");     arraylist<string> listinstitutenames = new arraylist<textview>();     jsonarray detailsarray = responseobject.getjsonarray("institutelist");      (int = 0; <detailsarray.length() ; i++) {            jsonobject obj = detailsarray.getjsonobject(i)            listinstitutenames.add(obj.getstring("institutename"))      }      autotextview = (autocompletetextview) findviewbyid(r.id.instname_field);     arrayadapter<string> arrayadapter = new arrayadapter<string>(this,                             android.r.layout.simple_list_item_1, listinstitutenames);     autotextview.setthreshold(1);     autotextview.setadapter(arrayadapter);      toast.maketext(getapplicationcontext(), "response successful",toast.length_long).show(); 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -