計算總量
回答
我已經解決了這個您只要致電從 父方法customadapter其執行你的總計算
喜歡這個((ParentClass) context).TotalCalculationfunctionToRun();
從加號或減號按鈕分別單擊
謝謝你abhishek – 2014-11-01 12:21:28
嘗試這樣可以幫助你,
private int getTotal(){
private int totalamount = 0;
for(int i = 1; i < list.getCount(); i++){
View view = list.getAdapter().getView(i, null, list);
TextView txt = (TextView) view.findViewById(R.id.yourid);
int amount = Integer.paserInt(txt.getText().toString())
totalamount += amount;
}
return totalamount;
}
但它如何幫助更新總在點擊的時候加或減號 – 2014-10-31 11:29:36
點擊該按鈕 – 2014-10-31 11:30:26
該按鈕是在列表視圖內 – 2014-10-31 11:31:04
我有一個解決方案的自定義適配器,可能是它可以讓你幫助
<TextView
android:id="@+id/cartTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="RS 0.00"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/cartTotal"
android:text="Total: "
android:textAppearance="?android:attr/textAppearanceMedium" />
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/textView2" />`
給定屏幕的適配器的設計佈局
<TextView
android:id="@+id/tiem_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:text="TextView"
android:textSize="20dp" />
<TextView
android:id="@+id/flag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:text="TextView"
android:textSize="20dp" />
<TextView
android:id="@+id/eachPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:text="120.0"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/ext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:text="Index Total Price"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="20dp"
android:orientation="horizontal">
<EditText
android:id="@+id/editText2"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
android:hint="Qty" />
<Button
android:id="@+id/plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/minus"
android:layout_alignBottom="@+id/minus"
android:layout_marginEnd="18dp"
android:layout_marginRight="18dp"
android:layout_toLeftOf="@+id/minus"
android:layout_toStartOf="@+id/minus"
android:text="+" />
<Button
android:id="@+id/minus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText2"
android:layout_alignBottom="@+id/editText2"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:text="-" />
</RelativeLayout>
模型項
public class CartItem {
String name;
String flag;
int UserQty;
double ProductPrice;
double ProductSalePrice;
private Double ext = 0.00;
public Double getExt() {
return ext;
}
public void setExt(Double ext) {
this.ext = ext;
}
public double getProductSalePrice() {
return ProductSalePrice;
}
public void setProductSalePrice(double productSalePrice) {
ProductSalePrice = productSalePrice;
}
public double getProductPrice() {
return ProductPrice;
}
public void setProductPrice(double productPrice) {
ProductPrice = productPrice;
}
public int getUserQty() {
return UserQty;
}
public void setUserQty(int userQty) {
UserQty = userQty;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
}
**Main Activity**
公共類MainActivity延伸活動{ 字符串URL = 「http://139.59.43.252/cnsgoCash/api/ws/controller/?access=true&action=get_category_by_product_list&id=5」; ProgressDialog PD; 按鈕付款;
private ExpandListAdapter ExpAdapter;
private ExpandableListView ExpandList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
payment=(Button)findViewById(R.id.payment);
ExpandList = (ExpandableListView) findViewById(R.id.expandableListView);
PD = new ProgressDialog(this);
PD.setMessage("Loading.....");
PD.setCancelable(false);
makejsonobjreq();
/* Click*/
payment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent in =new Intent(MainActivity.this,AddedItemActivity.class);
startActivity(in);
}
});
ExpandList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
}
});
}
private void makejsonobjreq() {
PD.show();
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
System.out.println("Json String :" + String.valueOf(response));
Log.e("RES", String.valueOf(response));
ArrayList<Group> list = new ArrayList<Group>();
ArrayList<Child> ch_list;
try {
//Iterator<String> key = response.keys();
JSONArray jsonArray=response.getJSONArray("data");
for(int i=0;i<jsonArray.length();i++){
JSONObject object= jsonArray.getJSONObject(i) ;
String k = object.getString("categoryName");
Log.e("Parent","hello"+k);
Group gru = new Group();
gru.setName(k);
ch_list = new ArrayList<Child>();
JSONArray ja = object.getJSONArray("productdetails");
for (int j = 0; j < ja.length(); j++) {
JSONObject jo = ja.getJSONObject(j);
Child ch = new Child();
//Log.e("Child","hello"+jo.getString("productName"));
ch.setName(jo.getString("productCode"));
ch.setFlag(jo.getString("productName"));
ch.setUserQty(jo.getString("quantity"));
ch.setProductPrice(jo.getString("sellPrice"));
ch_list.add(ch);
} // child for loop end
gru.setItems(ch_list);
list.add(gru);
}
ExpAdapter = new ExpandListAdapter(MainActivity.this, list);
ExpandList.setAdapter(ExpAdapter);
PD.dismiss();
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jsonObjectRequest);
}
}
- 1. 計算總量
- 2. 計算變量的總和
- 3. 根據計量單位和計算總和計算
- 4. 計算總計值
- 5. 總計差額並計算總計
- 6. 計算總排
- 7. 計算總和
- 8. 總數計算
- 9. 計算總和
- 10. 計算總價
- 11. 如何計算電池的總容量
- 12. 總數量與jQuery計算插件
- 13. 如何計算運行總量?
- 14. Yii框架....計算飛行總量
- 15. 在Wordpress中計算總分類數量?
- 16. 計算兩個變量的總和
- 17. Vue 2 - 計算行的總輸入量
- 18. 用javascript計算總計(onkeyup)
- 19. 去年的計算總計
- 20. Javascript - 計算貨幣總計
- 21. 計算總計查詢集
- 22. 計算預訂表總計
- 23. C#MVVM計算總計
- 24. SQL總和計算
- 25. 計算總小時
- 26. 計算總工時
- 27. 計算總小時
- 28. JQuery:計算插件不計算總價
- 29. Jmeter總報告總吞吐量 - 如何計算
- 30. 如何使用集合運算符計算總和*數量?
請向我們提供您的代碼塊你嘗試過什麼,你面臨 – Pratik 2014-10-31 11:24:25
問題我所做的是什麼,我都要求從定製適配器上的加號按鈕點擊,但它的功能更新時,活動從午餐切換到早餐,我想在點擊@ PRATIK – 2014-10-31 11:27:03
的時間來更新@Pratik請給一些想法,以更新 – 2014-10-31 11:57:34