android - get position in autocompletetextview -


i have 2 autocompletetextviews,in first autocompletetextview getting items server using json,the following response that

{"status":"success","clientlist":[{"cid":"1","name":"margi"},{"cid":"2","name":"steven"}],"productboxtype":[{"pbxid":"1","pbxname":"1 dozen","qtyperbox":"12"},{"pbxid":"2","pbxname":"2 dozens","qtyperbox":"24"},{"pbxid":"3","pbxname":"3 dozens","qtyperbox":"36"}]} 

i able names in first autocomplete , works fine,

now issue suppose user select item "margi" , cid 1,so again sending request server , trying productnames of 'margi',and response

{"status":"success","clientproduct":[{"pid":"4","name":"kangan pair","unitprice":"1500","boxqty":"1","bulkprice":[{"minqty":"10","price":"1500"},{"minqty":"15","price":"1470"},{"minqty":"20","price":"1460"}]}]} 

myactivity.java

public class mainactivity extends activity { private autocompletetextview actextview; private string catidtemp; jsonparser jsonparser = new jsonparser(); private autocompletetextview autoproduct; private static final string feedback_url = ""; private static final string feedback_success = "status"; @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      actextview = (autocompletetextview) findviewbyid(r.id.autocmplte_clorder_clname);     actextview.setadapter(new suggestionadapterclientlist(this,actextview.gettext().tostring()));      autoproduct=(autocompletetextview)findviewbyid(r.id.autocmplte_clorder_product);     autoproduct.setadapter(new suggestionadapterclientproduct(this, autoproduct.gettext().tostring()));      actextview.setonitemclicklistener(new onitemclicklistener() {            @override         public void onitemclick(adapterview<?> parent, view view,                 int position, long id) {             // todo auto-generated method stub             jsonparseclientproduct jp=new jsonparseclientproduct();               list<suggestgetsetclientproduct> list1 =jp.getparsejsonwcf(                                                 autoproduct.gettext().tostring());               new attemptlogin(list1.get(position).getid()).execute();         }     });  }    class attemptlogin extends asynctask<string, string, string> {      boolean failure = false;     private progressdialog pdialog;      private int selected_cid=1;     attemptlogin(int selected_cid){     this.selected_cid=selected_cid;     }       @override     protected void onpreexecute() {         super.onpreexecute();         pdialog = new progressdialog(mainactivity.this);         pdialog.setmessage("sending..");         pdialog.setindeterminate(true);       //  pdialog.setindeterminatedrawable(getresources().getdrawable(r.drawable.custom_progress));         pdialog.setcancelable(true);         pdialog.show();     }      @suppresswarnings("unused")     @override     protected string doinbackground(string...args) {         //check success tag         //int success;         looper.prepare();             try {               jsonparseclientlist jp=new jsonparseclientlist();                 list<namevaluepair> params = new arraylist<namevaluepair>();              list<suggestgetsetclientlist> list =jp.getparsejsonwcf(actextview.gettext().tostring());                   for(int = 0;i<list.size();i++)                  {                    if(list.get(i).getname().equals(actextview.gettext().tostring()))                    // params.add(new basicnamevaluepair("cid",list.get(i).getid()));                         params.add(new basicnamevaluepair("cid",selected_cid);                       //  catid=list.get(i).getid();                   // catidtemp=list.get(i).getid();                    }                   catidtemp=list.get(0).id.tostring();             // catidtemp=list.get(i).getid();              system.out.println("cattttttiiiiddd????"+catidtemp);              params.add(new basicnamevaluepair("action", "clientproduct"));               system.out.println("su gayu server ma????"+params);               log.d("request!", "starting");              // getting product details making http request              jsonobject json = jsonparser.makehttprequest (                  feedback_url, "post", params);              //check log json response              log.d("login attempt", json.tostring());               jsonobject jobj = new jsonobject(json.tostring());              final string msg = jobj.getstring("msg");                  return json.getstring(feedback_success);           }catch (jsonexception e) {              e.printstacktrace();          }          return null;     }      // after completing background task dismiss progress dialog      protected void onpostexecute(string file_url) {         //dismiss dialog once product deleted         pdialog.dismiss();          //parentcat.gettext().clear(); }}   public class suggestgetsetclientproduct {          string id,name;         public suggestgetsetclientproduct(string id, string name){             this.setid(id);             this.setname(name);         }         public string getid() {             return id;         }          public void setid(string id) {             this.id = id;         }          public string getname() {             return name;         }          public void setname(string name) {             this.name = name;         }     }     public class jsonparseclientproduct {           double current_latitude,current_longitude;         public jsonparseclientproduct(){}         public jsonparseclientproduct(double current_latitude,double current_longitude){             this.current_latitude=current_latitude;             this.current_longitude=current_longitude;         }         public list<suggestgetsetclientproduct> getparsejsonwcf(string sname)            {             list<suggestgetsetclientproduct> listdata = new arraylist<suggestgetsetclientproduct>();             try {                string temp=sname.replace(" ", "%20");                url js = new url("");                 system.out.println("what fuck"+js);                urlconnection jc = js.openconnection();                bufferedreader reader = new bufferedreader(new inputstreamreader(jc.getinputstream()));                string line = reader.readline();                jsonobject jsonresponse = new jsonobject(line);                jsonarray jsonarray = jsonresponse.getjsonarray("clientproduct");                for(int = 0; < jsonarray.length(); i++){                    jsonobject r = jsonarray.getjsonobject(i);                    listdata.add(new suggestgetsetclientproduct(r.getstring("pid"),r.getstring("name")));                }              } catch (exception e1) {                // todo auto-generated catch block                e1.printstacktrace();            }             return listdata;             }     }     public class suggestionadapterclientproduct extends arrayadapter<string>{           protected static final string tag = "suggestionadapter";         private list<string> suggestions;         public suggestionadapterclientproduct(activity context, string namefilter) {             super(context, android.r.layout.simple_dropdown_item_1line);             suggestions = new arraylist<string>();         }          @override         public int getcount() {             return suggestions.size();         }          @override         public string getitem(int index) {             return suggestions.get(index);         }          @override         public filter getfilter() {             filter myfilter = new filter() {                 @override                 protected filterresults performfiltering(charsequence constraint) {                     filterresults filterresults = new filterresults();                     jsonparseclientproduct jp=new jsonparseclientproduct();                     if (constraint != null) {                         // class queries web api, parses data ,                         // returns arraylist<goeurogetset>                         list<suggestgetsetclientproduct> new_suggestions =jp.getparsejsonwcf(constraint.tostring());                         suggestions.clear();                         /*for (int i=0;i<new_suggestions.size();i++) {                         suggestions.add(new_suggestions.get(i).getname());                     }*/                      (int i=0;i<new_suggestions.size();i++) {                         string name=new_suggestions.get(i).getname();                         string id=new_suggestions.get(i).getid();                         system.out.println("checis id"+id);                         if(name.contains(constraint)){                         suggestions.add(new_suggestions.get(i).getname());                              }                        }                         // assign values , count filterresults                         // object                         filterresults.values = suggestions;                         filterresults.count = suggestions.size();                     }                     return filterresults;                 }                  @override                 protected void publishresults(charsequence contraint,                         filterresults results) {                     if (results != null && results.count > 0) {                         notifydatasetchanged();                     } else {                         notifydatasetinvalidated();                     }                 }             };             return myfilter;         }     } 

}

issue here..i not able position of id..

 try {               jsonparseclientlist jp=new jsonparseclientlist();                 list<namevaluepair> params = new arraylist<namevaluepair>();              list<suggestgetsetclientlist> list =jp.getparsejsonwcf(actextview.gettext().tostring());                   for(int = 0;i<list.size();i++)                  {                    if(list.get(i).getname().equals(actextview.gettext().tostring()))                     params.add(new basicnamevaluepair("cid",list.get(i).getid()));                       //  catid=list.get(i).getid();                   }                   for(int b=0;b<list.size();b++)                  {                      catidtemp=list.get(0).id.tostring();                      system.out.println("cattttttiiiiddd????"+catidtemp);                  } 

use list1 getting selected cid listview:

@override   public void onitemclick(adapterview<?> parent, view view,                 int position, long id) {             // todo auto-generated method stub       jsonparseclientproduct jp=new jsonparseclientproduct();       list<suggestgetsetclientproduct> list1 =jp.getparsejsonwcf(                                         autoproduct.gettext().tostring());       new attemptlogin(list1.get(position).getid()).execute(); } 

and create constructor in attemptlogin class:

class attemptlogin extends asynctask<string, string, string> {      boolean failure = false;     private progressdialog pdialog;     private int selected_cid=1;     attemptlogin(int selected_cid){     this.selected_cid=selected_cid;     }    //... code  } 

now use selected_cid add cid parameter :

params.add(new basicnamevaluepair("cid",selected_cid); 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -