java - Same data from listview being printed multiple times -


this java activity.the data being retrieve server. based on system.out.println("hi" +co.transaction_id), same item being printed 5 times. java problem or php problem. have try edit listview xml height match parent or fill parent doesn't help.

public class connect4 extends asynctask<string, void, string> { // public static final string product_id = "product_id"; public static final string receipt_index = "receipt_index"; view view; activity activity; productadapter1 adapter; public list<contactobject> receipt = new arraylist<>();   bitmap bitmap;  public connect4(activity activity, view v, productadapter1 a) {     this.activity = activity;     view = v;     adapter = a; }  string convertstreamtostring(inputstream is) {     try {         return new java.util.scanner(is).usedelimiter("\\a").next();     } catch (java.util.nosuchelementexception e) {         return "";     } } protected string doinbackground(string... arg0) {     string ipaddress = "http://10.207.140.22/apexstore2/";     try {         url url = new url(ipaddress +"receipt.php");         string urlparameters =                 urlencoder.encode("user_id", "utf-8") + "=" +    urlencoder.encode(arg0[0], "utf-8") + "&" +                         urlencoder.encode("shipping_name", "utf-8") + "=" +    urlencoder.encode("???", "utf-8") + "&" +                         urlencoder.encode("shipping_address", "utf-8") + "="  + urlencoder.encode("???", "utf-8")+ "&" +                         urlencoder.encode("shipping_contact", "utf-8") + "="   + urlencoder.encode("???", "utf-8")+ "&" +                         urlencoder.encode("shipping_email", "utf-8") + "=" +   urlencoder.encode("???", "utf-8")+ "&" +                         urlencoder.encode("order_date", "utf-8") + "=" +   urlencoder.encode("???", "utf-8")+ "&" +                         urlencoder.encode("trx_id", "utf-8") + "=" +   urlencoder.encode("???", "utf-8")+ "&" +                         urlencoder.encode("tracking_num", "utf-8") + "=" +  urlencoder.encode("???", "utf-8")+ "&" +                         urlencoder.encode("quantity", "utf-8") + "=" +   urlencoder.encode("???", "utf-8")+ "&" +                         urlencoder.encode("product_id", "utf-8") + "=" +    urlencoder.encode("???", "utf-8")+ "&" +                         urlencoder.encode("product_title", "utf-8") + "=" +   urlencoder.encode("???", "utf-8")+ "&" +                         urlencoder.encode("product_price", "utf-8") + "=" +    urlencoder.encode("???", "utf-8")+ "&" +                         urlencoder.encode("product_img1", "utf-8") + "=" +    urlencoder.encode("???", "utf-8");          httpurlconnection connection = (httpurlconnection)     url.openconnection();          connection.setrequestmethod("post");         connection.setrequestproperty("content-type",                 "application/x-www-form-urlencoded");          connection.setrequestproperty("content-length", "" +                 integer.tostring(urlparameters.getbytes().length));         connection.setrequestproperty("content-language", "en-us");          connection.setusecaches(false);         connection.setdoinput(true);         connection.setdooutput(true);          //send request         dataoutputstream wr = new dataoutputstream (                 connection.getoutputstream ());         wr.writebytes (urlparameters);         wr.flush ();         wr.close ();          //get response         inputstream = connection.getinputstream();         bufferedreader rd = new bufferedreader(new inputstreamreader(is));         string line;         stringbuffer response = new stringbuffer();         while((line = rd.readline()) != null) {             response.append(line);             response.append('\r');         }         rd.close();         //system.out.println(response.tostring());          jsonobject mainobject = new jsonobject(response.tostring());         jsonarray uniobject = mainobject.getjsonarray("result");         for(int = 0; < uniobject.length(); i++) {             contactobject co = new contactobject();             jsonobject rowobject = uniobject.getjsonobject(i);             //eventobject co = new eventobject();             //co.user_id = rowobject.getstring("user_id");             co.name = rowobject.getstring("shipping_name");             co.address = rowobject.getstring("shipping_address");             co.contact = rowobject.getstring("shipping_contact");             co.email = rowobject.getstring("shipping_email");             co.orderdate = rowobject.getstring("order_date");             co.transaction_id = rowobject.getstring("trx_id");             co.tracking_id = rowobject.getstring("tracking_num");             co.quantity = rowobject.getstring("quantity");             co.product_id = rowobject.getstring("product_id");             co.product_title = rowobject.getstring("product_title");             co.product_price = rowobject.getstring("product_price");             co.img1 = ipaddress +"img/products/" +  rowobject.getstring("product_img1");             //mcontentitems.add(co);             system.out.println("hi" +co.transaction_id);             receipt.add(new contactobject(co.name, co.address, co.contact,  co.email, co.orderdate, co.transaction_id, co.tracking_id, co.quantity,  co.product_id, co.product_title, co.product_price, co.img1));             //         userlogin(co.product_id);         }          //to further break down json         //jsonobject oneobject = mainobject.getjsonobject("1");         //string id = oneobject.getjsonobject("id");         try{          }         finally{             connection.disconnect();         }     } catch (exception e){         system.out.println(e.tostring());     }     return ""; }  protected void onpreexecute(){  }  @override protected void onpostexecute(string result){     adapter.receipt = receipt;     adapter.notifydatasetchanged(); }    private class loadimage extends asynctask<string, string, bitmap> {     imageview img;     public loadimage(imageview img){         this.img = img;     }      @override     protected void onpreexecute() {         super.onpreexecute();      }     protected bitmap doinbackground(string... args) {         try {             bitmap = bitmapfactory.decodestream((inputstream) new  url(args[0]).getcontent());          } catch (exception e) {             e.printstacktrace();         }         return bitmap;     }      protected void onpostexecute(bitmap image) {          if(image != null){             img.setimagebitmap(image);         }else{         }     } } } 

this php script.

<?php  include ('classes/functions.php');   if(isset($_post['user_id'])){ $user_id = $_post['user_id']; $check_receipt = "select  si.shipping_name,     si.shipping_address,     si.shipping_contact,     si.shipping_email,     o.order_date,     o.trx_id,     o.tracking_num,     o.quantity,     o.product_id,     p.product_title,     p.product_price,     p.product_img1  shipping_infos si  inner join orders o  on si.user_id = o.user_id inner join products p on p.product_id =      o.product_id     si.user_id='".$user_id."';";          $run_receipt_checking = mysqli_query($con, $check_receipt);         $result = array();     while($row = mysqli_fetch_array($run_receipt_checking)){     array_push($result,     array(           'shipping_name'=>$row[0],           'shipping_address'=>$row[1],           'shipping_contact'=>$row[2],           'shipping_email'=>$row[3],           'order_date'=>$row[4],           'trx_id'=>$row[5],           'tracking_num'=>$row[6],             'quantity'=>$row[7],           'product_id'=>$row[8],           'product_title'=>$row[9],                      'product_price'=>$row[10],           'product_img1'=>$row[11]              )); } echo json_encode(array("result"=>$result));  } ?> 

i not sure 100% facing same problem when deal custom adapter. problem solved correcting code in getview() of custom adapter.

may help.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -