AutoCompleteTextView using JSON in Android -


i'm trying extract json array autocompletetextview i'm getting each value twice in drop down.

json:

{"names":[{"id":"1","names":"jacob"},{"id":"2","names":"amy"},{"id":"3","names":"melissa"}],"success":1,"message":"successfully found "}  

class ajax:

class ajax5 extends asynctask<string, string, string> {// json starts here      // new createnewproduct().execute();      protected arraylist<namevaluepair> parameters;     jsonobject json;      public ajax5() {         super();         parameters = new arraylist<namevaluepair>();      }      @override     protected void onpreexecute() {         super.onpreexecute();      }      protected string doinbackground(string... args) {          jsonparser jparser = new jsonparser();         json = jparser                 .makehttprequest(                         "http:link.php",                         "get", this.parameters);          try {             log.d("create response", "four"                     + json.getjsonobject("1").tostring());         } catch (jsonexception e) {             e.printstacktrace();         }          return null;     }      protected void onpostexecute(string file_url) {         try{         jsonarray jarray=json.getjsonarray("names");         pickname = new arraylist<treemap<string, string>>();         //treemap<string, treemap<string, string>> tempmap = new treemap<string, treemap<string, string>>();         for(int i=0;i<jarray.length();i++){             treemap<string,string> valuepairs=new treemap<string,string>();             jsonobject tempobj=jarray.getjsonobject(i);             valuepairs.put("key", tempobj.getstring("names"));             valuepairs.put("value", tempobj.getstring("names"));             pickpinn.add(valuepairs);          }                     }          catch (jsonexception e) {                 e.printstacktrace();             }         log.d("name", pickpinn.tostring());         //routes.addall(vehicles.values());         simpleadapter sp5_adapter = new simpleadapter(onlinebooking.this, pickpinn,                 r.layout.runner, new string[] { "key", "value" },                  new int[] { r.id.name_id, r.id.name_value });         // sp1_adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);         actv1.setadapter(sp5_adapter);          actv1.addtextchangedlistener(onlinebooking.this);         actv1.setonitemclicklistener(new onitemclicklistener() {              @override             public void onitemclick(adapterview<?> arg0, view v, int arg2,                     long arg3) {                  textview stv = (textview) v.findviewbyid(r.id.name_id);                 string route_id_string = stv.gettext().tostring();                 edsp5.settext(route_id_string);                 actv1.settext(((textview) v.findviewbyid(r.id.name_value))                         .gettext().tostring());               }          });      } } 

how fix this? thanks.

you need change from

    jsonarray jarray=json.getjsonarray("names");     pickname = new arraylist<treemap<string, string>>();     //treemap<string, treemap<string, string>> tempmap = new treemap<string, treemap<string, string>>();     for(int i=0;i<jarray.length();i++){         treemap<string,string> valuepairs=new treemap<string,string>();         jsonobject tempobj=jarray.getjsonobject(i);         valuepairs.put("key", tempobj.getstring("names"));         valuepairs.put("value", tempobj.getstring("names"));         pickpinn.add(valuepairs);      } 

to

     jsonarray jarray=json.getjsonarray("names");      pickname = new arraylist<treemap<string, string>>();     //treemap<string, treemap<string, string>> tempmap = new treemap<string, treemap<string, string>>();     for(int i=0;i<jarray.length();i++){         treemap<string,string> valuepairs=new treemap<string,string>();         jsonobject tempobj=jarray.getjsonobject(i);         valuepairs.put("id", tempobj.getstring("id"));         valuepairs.put("names", tempobj.getstring("names"));         pickpinn.add(valuepairs);      } 

also here

  simpleadapter sp5_adapter = new simpleadapter(onlinebooking.this, pickpinn,             r.layout.runner, new string[] { "key", "value" },              new int[] { r.id.name_id, r.id.name_value }); 

to

  simpleadapter sp5_adapter = new simpleadapter(onlinebooking.this, pickpinn,             r.layout.runner, new string[] { "id", "names" },              new int[] { r.id.name_id, r.id.name_value }); 

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? -