Recyclerview addOnItemTouchListener Android购物车-Android RecyclerView

时间:2018-12-12 05:03:24

标签: android android-recyclerview android-volley shopping-cart

我需要单击添加购物车项目。 现在我要双击以添加购物车物品
我该怎么解决...

productsList.add(cart); ModelCart.setData(productsList);


RecyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getApplicationContext(), new RecyclerItemClickListener.OnItemClickListener() {
                    @Override
                    public void onItemClick(View view, final int position) {
                        Cart cart = new Cart();
                        if (listItems.get(position).getQnty() == 0){
                            Log.d("TAG", "getQnty :"+listItems.get(position).getQnty()+" is ZERO");
                        }else {
                            double abcd = listItems.get(position).getSalePrice()*listItems.get(position).getQnty();
                            cart.setProductName(listItems.get(position).getProductName());
                            cart.setPrice(abcd);
                            cart.setSalePrice(listItems.get(position).getSalePrice());
                            cart.setId(listItems.get(position).getId());
                            cart.setQnty(listItems.get(position).getQnty());
                            productsList.add(cart);
                            ModelCart.setData(productsList);
                            }
                        List<Cart> data = ModelCart.getData();
                        int total = 0;
                        Log.d("TAG", "start total = " +total);
                        for (int i = 0; i < data.size(); i++) {
                            Log.d("TAG", "at "+i+ " quantity = " +data.get(i).getQnty());
                            total += data.get(i).getQnty() * data.get(i).getSalePrice();
                            Log.d("TAG", "at "+i+ " total = " +total);
                         }
                        TextTotal.setText("" +total);

                    }
                })
        );

0 个答案:

没有答案