如何将一项添加到其他recyclerview

时间:2019-09-01 13:35:12

标签: java android recycler-adapter

我想将rvone项发送到rvtwo,但只有一个值

我有一个像这样的物品

title
Rp. 1000 x 4 pcs

4000 //thistotal

如果单击该项目,它将变为

title
Rp. 1000 x 1 pcs

Rp.1000 //thistotal

这里是我的适配器rv_one

public void onBindViewHolder(@NonNull final OrderViewHolder holder, final int position) {
    final OrderModel orderModel = orderModels.get(0);

    final Long id = orderModel.getOrderDetailModels().get(position).getId();
    final String itemName = orderModel.getOrderDetailModels().get(position).getItem();
    final long price = orderModel.getOrderDetailModels().get(position).getPrice();
    final long quantity = orderModel.getOrderDetailModels().get(position).getQuantity();
    final long amount = orderModel.getOrderDetailModels().get(position).getAmount();

    holder.mTxt_item.setText(orderModel.getOrderDetailModels().get(position).getItem());
    holder.mTxt_price.setText(String.valueOf(orderModel.getOrderDetailModels().get(position).getPrice()));
    holder.mTxt_quantity.setText(String.valueOf(orderModel.getOrderDetailModels().get(position).getQuantity()));
    holder.mTxt_amount.setText(String.valueOf(orderModel.getOrderDetailModels().get(position).getAmount()));

    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (quantity <= 1){
                orderModels.get(0).getOrderDetailModels().remove(position);
                notifyItemRemoved(position);
                notifyItemRangeChanged(position,orderModels.get(0).getOrderDetailModels().size());
            } else {

                orderModel.getOrderDetailModels().get(position).setQuantity(quantity - 1);
                orderModel.getOrderDetailModels().get(position).setAmount(price * quantity);
                notifyDataSetChanged();

                OrderCatchModel orderCatchModel = new OrderCatchModel();
                orderCatchModel.setId(id);
                orderCatchModel.setItem(itemName);
                orderCatchModel.setPrice(price);
                orderCatchModel.setQuantity(quantity);
                orderCatchModel.setAmount(amount);

                orderCatchModels.add(orderCatchModel);

                if (context instanceof OrderActivity) {
                    ((OrderActivity)context).addItem(orderCatchModels);
                }
            }
        }
    }
}

以及此方法可添加1个数据

public void addItem(List<OrderCatchModel> orderCatchModels) {
    orderCatchAdapter = new OrderCatchAdapter(this, orderCatchModels);
    LinearLayoutManager linearLayoutManagerRvTwo = new LinearLayoutManager(this);

    rv_two.setLayoutManager(linearLayoutManagerRvTwo);
    rv_two.setAdapter(orderCatchAdapter);


    orderCatchAdapter.notifyItemInserted(itemPosition);
    orderCatchAdapter.notifyItemRangeChanged(itemPosition ,orderDetailModels.size());

//    orderCatchAdapter.notifyItemChanged(pos);
    itemPosition += 1;

}

但它只是将完整的数据发送到rv_two,而不是我想要的

我希望这样的输出

title
Rp. 1000 x 1 pcs

Rp.1000 //thistotal

0 个答案:

没有答案