我使用 volley 库并从服务器加载 json 并将其显示在 recyclerview 中。我想创建一个购物车并计算 recyclerview 项目的总价。我的问题是没有计算物品的总成本。
请帮帮我
这是我的代码:
public class checkout extends AppCompatActivity {
String shop = SHOP;
List<Product6> productList6;
ProductsAdapter6 productsAdapter6;
RecyclerView recyclerView;
private ProductsAdapter6 adapter6;
private GridLayoutManager layoutManager;
RecyclerView.LayoutManager RecyclerViewLayoutManager;
private TextView subTotal;
private double mSubTotal = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_checkout);
recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
recyclerView.setHasFixedSize(true);
RecyclerViewLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(RecyclerViewLayoutManager);
adschild2();
productList6 = new ArrayList<>();
subTotal = (TextView) findViewById(R.id.sub_total);
mSubTotal = grandTotal(productList6);
subTotal.setText(String.valueOf(mSubTotal));
}
private int grandTotal(List<Product6> items) {
int totalPrice = 0;
for (int i = 0; i < items.size(); i++) {
totalPrice += items.get(i).getBack();
}
return totalPrice;
}
private void adschild2() {
StringRequest stringRequest = new StringRequest(Request.Method.GET, shop, new Response.Listener<String>()
aluckdog
相关分类