|
![](/images/resource/spacer.gif) |
|
จะหาผลรวมของราคา ใน andriod Listview json ต้องทำอย่างไรบ้างครับ |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
รบกวนด้วยครับ จะหาผลรวมของราคา ใน andriod Listview json ต้องทำอย่างไรบ้างครับ ตอนนี้มันโชว์รายการทุกรายการแล้ว แต่ผลรวมยังไม่มีครับ โค๊ตที่ใช้ครับ
Code
try {
JSONArray data = new JSONArray(getJSONUrl(url,params));
MyArrList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
for(int i = 0; i < data.length(); i++){
JSONObject c = data.getJSONObject(i);
map = new HashMap<String, String>();
map.put("MemberID", c.getString("MemberID"));
map.put("Username", c.getString("Username2"));
map.put("Password", c.getString("Password"));
map.put("Name", c.getString("Name"));
map.put("Amount", c.getString("amount"));
map.put("Qty", c.getString("Qty"));
//ต้องการแสดงผลรวมของ "amount" ต้องเขียนประมาณไหนครับ
MyArrList.add(map);
}
lisView1.setAdapter(new ImageAdapter(this));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Tag : Mobile, MySQL, Android, JAVA
![](/images/adv.jpg?v=1001)
|
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2019-09-10 10:56:38 |
By :
sranuwat |
View :
598 |
Reply :
1 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ได้แล้วครับ ปรับแก้ตามนี้ครับ
Code
try {
JSONArray data = new JSONArray(getJSONUrl(url,params));
MyArrList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
int SumAmount=0;
int SumQty=0;
for(int i = 0; i < data.length(); i++){
JSONObject c = data.getJSONObject(i);
map = new HashMap<String, String>();
map.put("MemberID", c.getString("MemberID"));
map.put("Username", c.getString("Username2"));
map.put("Password", c.getString("Password"));
map.put("Name", c.getString("Name"));
map.put("Amount", c.getString("Amount"));
map.put("Qty", c.getString("Qty"));
SumQty += Integer.parseInt(c.getString("Qty"));
SumAmount += Integer.parseInt(c.getString("Amount"));
MyArrList.add(map);
}
// แสดงยอดรวม.
textView.setText(String.valueOf(SumQty));
textView2.setText(String.valueOf(SumAmount));
lisView1.setAdapter(new ImageAdapter(this));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2019-09-10 13:16:17 |
By :
sranuwat |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 04
|