android - How to compare integer field with json field? -


i have following json response,from response getting unitprice , boxqty, 1500 , 1 in 2 different edittext,now trying if user change boxqty 1 15,then unit price should change 1500 1470,following code snippet,

{"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"}]}]} 

mainactivity.java

     @override     protected string doinbackground(string...args) {         //check success tag         //int success;         looper.prepare();           try {              list<namevaluepair> params = new arraylist<namevaluepair>();              params.add(new basicnamevaluepair("cid",letss));              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());             if (json != null) {                 try {                     jsonobject jsonobj = new jsonobject(json.tostring());                     // getting json array node                     clientproduct = jsonobj.getjsonarray(clientproduct_list);                     // looping through contacts                     (int = 0; < clientproduct.length(); i++) {                        ck = clientproduct.getjsonobject(i);                        unitp=ck.getstring("unitprice");                         system.out.println("unit ni price"+unitp);                        boxq=ck.getstring("boxqty");                         system.out.println("box ni quantity "+boxq);                          bulkprice = ck.getjsonarray(bulkprice_list);                          allqtys=new arraylist<integer>();                          (int b=0 ; b < bulkprice.length(); b++)                          {                              jo = bulkprice.getjsonobject(b);                             minimum_qty=jo.getint("minqty");                         allqtys.add(minimum_qty);                             /* allqtys=new arraylist<string>();                            allqtys.add(minimum_qty.tostring());                           system.out.println("all minquantitiy"+minimum_qty);*/                      system.out.println("all minquantitiy"+allqtys);                        system.out.println("minquantitiy"+minimum_qty);                             pricess=jo.getstring("price");                             system.out.println("box price "+pricess);                           }                          /*conrs=integer.parseint(allqtys.tostring());                          system.out.println("integer converted arrray"+conrs);*/                          /* newlist = new arraylist<integer>(allqtys.size()) ;                          (string myint : allqtys)                           {                             newlist.add(integer.valueof(myint));                           }                          system.out.println("allqtys "+newlist);*/                          system.out.println("not null");                     }                 } catch (jsonexception e) {                     e.printstacktrace();                 }             } else {                 log.e("servicehandler", "couldn't data url");             }            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();         /* arraylist<integer> allval=new arraylist<integer>();        // allval.add(minimum_qty);        system.out.println("integer converted arraylist"+allval);*/           autoproduct.setonitemclicklistener(new onitemclicklistener() {              @override             public void onitemclick(adapterview<?> parent, view view,                     int position, long id) {                 // todo auto-generated method stub                 // uprice.settext(unitp);                     //bxqtyy.settext(boxq);             }         });           bxqtyy.addtextchangedlistener(new textwatcher() {              @override             public void ontextchanged(charsequence s, int start, int before, int count) {                 // todo auto-generated method stub                 if(integer.parseint(bxqtyy.gettext().tostring()) > integer.parseint(allqtys.get(index)))                 {                     if(bxqtyy.gettext().equals(null))                     {                         uprice.settext(unitp);                     }                     uprice.settext("1470");                     //system.out.println("lets check");                 }                 else                 {                     uprice.settext("1500");                     system.out.println("lets check");                 }             }              @override             public void beforetextchanged(charsequence s, int start, int count,                     int after) {             }              @override             public void aftertextchanged(editable s) {              }         });  }} 

this line if(bxqtyy.gettext().tostring() > minimum_qty.compareto(box_qty)) not working because can't compare string integer, ">" operator throw compile time error.

use this

integer.parseint(your text here); 

and proper code it

if(integer.parseint(bxqtyy.gettext().tostring()) > minimum_qty.compareto(box_qty))     {      } 

hope help.