2017-08-07 4 views
0

私はデータベースから注文リストを表示する必要があるListVewを持っていました.Mysqlデータベースに複数の注文がありますが、ListVew.Anyヘルプで1つの注文だけが連続して繰り返されています感謝。ListVew AndroidのMySqlデータベースから同じ行を繰り返す

ここに私のアダプタクラスです

public class OrderApprovalAdapter extends ArrayAdapter 
{ 
List list1 = new ArrayList(); 
Context context; 

public OrderApprovalAdapter(@NonNull Context context, @NonNull int Resource) 
{ 
    super(context, Resource); 
    this.context = context; 
} 
@Override 
public void add(@Nullable Object object) 
{ 
    super.add(object); 
    list1.add(object); 
} 

@Override 
public int getCount() 
{ 
    return list1.size(); 
} 

@Override 
public Object getItem(int position) 
{ 
    return list1.get(position); 
} 



@Override 
public long getItemId(int position) 
{ 
    return position; 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) 
{ 
    final OrderApprovalAdapter.ContactHolder contactHolder; 

    View row; 
    row = convertView; 

    if (row == null) 
    { 
     LayoutInflater layoutInflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     row = layoutInflater.inflate(R.layout.order_approval_format, parent, false); 
     contactHolder = new ContactHolder(); 
     contactHolder.date = (TextView) row.findViewById(R.id.invoice_date); 
     contactHolder.orderid = (TextView) row.findViewById(R.id.invoice_no); 
     contactHolder.shopname = (TextView) row.findViewById(R.id.shop_name); 
     contactHolder.ownername = (TextView) row.findViewById(R.id.owner_name); 
     contactHolder.mobile=(TextView) row.findViewById(R.id.mobile_noo); 
     contactHolder.location=(TextView)row.findViewById(R.id.location); 
     contactHolder.itemscount=(TextView)row.findViewById(R.id.items); 
     contactHolder.amount=(TextView)row.findViewById(R.id.total); 
     contactHolder.Approval=(Button)row.findViewById(R.id.Approve_btn); 
     contactHolder.Decline=(Button)row.findViewById(R.id.decline_btn); 



     row.setTag(contactHolder); 
    } else 
    { 
     contactHolder = (ContactHolder) row.getTag(); 
    } 


    final OrderApprovalDetails contacts = (OrderApprovalDetails) this.getItem(position); 
    contactHolder.date.setText(contacts.getDate()); 
    contactHolder.orderid.setText(contacts.getOrderid()); 
    contactHolder.shopname.setText(contacts.getShopname()); 
    contactHolder.ownername.setText(contacts.getOwnername()); 
    contactHolder.mobile.setText(contacts.getMobile()); 
    contactHolder.location.setText(contacts.getLocation()); 
    contactHolder.itemscount.setText(contacts.getItemscount()); 
    contactHolder.amount.setText(contacts.getAmount()); 
    contactHolder.Approval.setOnClickListener(new View.OnClickListener() 
    { 
     @Override 
     public void onClick(View v) 
     { 
      Toast.makeText(context, "Approved", Toast.LENGTH_SHORT).show(); 

     } 
    }); 
    contactHolder.Decline.setOnClickListener(new View.OnClickListener() 
    { 
     @Override 
     public void onClick(View v) 
     { 
      Toast.makeText(context, "Decline", Toast.LENGTH_SHORT).show(); 
     } 
    }); 

    return row; 
} 
static class ContactHolder 
{ 
    TextView date,orderid,shopname,ownername,mobile,location,itemscount,amount; 
    Button Approval,Decline; 

} 
} 

Retrivingデータの意図を通じて送信データベース

class OrdersListBackgroundTask extends AsyncTask<Void,Void,String> 
{ 

    @Override 
    protected void onPreExecute() 
    { 
     OrdersList_url="http://10.0.2.2/accounts/OrderForm2.php"; 
    } 

    @Override 
    protected String doInBackground(Void... params) 
    { 

     try { 
      URL url=new URL(OrdersList_url); 
      HttpURLConnection httpURLConnection= 
     (HttpURLConnection)url.openConnection(); 
      InputStream is= httpURLConnection.getInputStream(); 
      InputStreamReader isr=new InputStreamReader(is); 
      BufferedReader br=new BufferedReader(isr); 
      StringBuilder sb=new StringBuilder(); 

      while ((JSON_STRING4=br.readLine())!=null) 
      { 
       sb.append(JSON_STRING4+ ""); 
      } 

      br.close(); 
      is.close(); 
      httpURLConnection.disconnect(); 

      return sb.toString().trim(); 
     } catch (MalformedURLException e) 
     { 
      e.printStackTrace(); 
     } catch (IOException e) 
     { 
      e.printStackTrace(); 
     } 


     return null; 
    } 

    @Override 
    protected void onPostExecute(String result) 
    { 
     //TextView tv=(TextView)findViewById(R.id.tv); 
     //tv.setText(result); 
     json_string4=result; 
    } 
} 

から次のページへ

public void Orders_List(View v)//Button click 
    { 
    if (json_string4==null) 
    { 
     Toast.makeText(this, "Get Orders First", Toast.LENGTH_SHORT).show(); 
    }else 
    { 
     Intent i1=new Intent(this,OrdersList.class); 
     i1.putExtra("json_data4",json_string4); 
     startActivity(i1); 
    } 
    } 

MainActivity

での使用私は間違いをしたところ

OrderApprovalDetailsクラス

public class OrderApprovalDetails 
{ 
public static String 
date,orderid,shopname,ownername,mobile,location,itemscount,amount; 
public static Button Approval,Decline; 

public OrderApprovalDetails(String date,String orderid,String shopname,String ownername,String mobile,String location,String itemscount,String amount,Button Approval,Button Decline) 
{ 
    this.setDate(date); 
    this.setOrderid(orderid); 
    this.setShopname(shopname); 
    this.setOwnername(ownername); 
    this.setMobile(mobile); 
    this.setLocation(location); 
    this.setItemscount(itemscount); 
    this.setAmount(amount); 
    this.setApproval(Approval); 
    this.setDecline(Decline); 
} 

public String getDate() 
{ 
    return date; 
} 

public static Button getApproval() { 
    return Approval; 
} 

public static void setApproval(Button approval) { 
    Approval = approval; 
} 

public static Button getDecline() { 
    return Decline; 
} 

public static void setDecline(Button decline) { 
    Decline = decline; 
} 

public void setDate(String date) { 
    this.date = date; 
} 

public String getOrderid() { 
    return orderid; 
} 

public void setOrderid(String orderid) { 
    this.orderid = orderid; 
} 

public String getShopname() { 
    return shopname; 
} 

public void setShopname(String shopname) { 
    this.shopname = shopname; 
} 

public String getOwnername() { 
    return ownername; 
} 

public void setOwnername(String ownername) { 
    this.ownername = ownername; 
} 

public String getMobile() { 
    return mobile; 
} 

public void setMobile(String mobile) { 
    this.mobile = mobile; 
} 

public String getLocation() { 
    return location; 
} 

public void setLocation(String location) { 
    this.location = location; 
} 

public String getItemscount() { 
    return itemscount; 
} 

public void setItemscount(String itemscount) { 
    this.itemscount = itemscount; 
} 

public String getAmount() { 
    return amount; 
} 

public void setAmount(String amount) { 
    this.amount = amount; 
} 

}

は知ってはいけない、私はそれをfindoutするために事前に感謝を助けてください。あなたがここに行ったよう

+0

への変更これは、あなたは –

+0

同様にあなたのOrderApprovalDetailsクラスのコードを追加することができます貼り付けてくださいデータベースからデータを取り出すためのロジック? –

+0

はい私はOrderApprovalDetailsクラスのコードを追加しました@kapsym –

答えて

1

あなたのクラスのメンバーは静的宣言すべきではありません -

public class OrderApprovalDetails 
{ 
    public static String date,orderid,shopname,ownername,mobile,location,itemscount,amount; 

public class OrderApprovalDetails 
    { 
    public String date,orderid,shopname,ownername,mobile,location,itemscount,amount; 
+0

ありがとう、それは私のために働いた。 –

+0

私の答えを受け入れてください:) –

+0

仲間とありがとう:) –

関連する問題