如何从ArrayList添加价格

时间:2018-10-04 09:13:29

标签: android

ArrayList<ProductModel> products = new ArrayList<>();

我需要将某些食品的进餐价格和进餐数量相乘,得出总计。

所以,这是我的代码。请帮帮我

double totalPrices = Double.parseDouble(productModel.getMealprice()) + Double.parseDouble(productModel.getMealqty());

            for (int i = 0; i < products.size(); i++) {

                    totalPrices += products.get(i);
            }

            tv_totalamount.setText("Total Amount to be Paid : " + totalPrices + "");

1 个答案:

答案 0 :(得分:0)

一些小技巧可以解决您的问题。

double totalPrices = Double.parseDouble(productModel.getMealprice()) + Double.parseDouble(productModel.getMealqty());

                for (int i = 0; i < products.size(); i++) {

                        totalPrices += products.get(i).getPrice();
                }

                tv_totalamount.setText("Total Amount to be Paid : " + totalPrices + "");
相关问题