I'm working on a POS management system where user can choose an item from a product list and add the selected values in a check list. I can successfully add a new item to the check list after clicking on the product list, but can't update a check list item's quantity which is already added before. See the image for a clear demonstration,
From the image you can see that each product item was added as a new item in check list instead of updating the quantity.
I'm looking for a solution to update the check list quantity after clicking on a item from the product list.
Here's my on click listener for the product list recyclerview,
recyclerProducts.addOnItemTouchListener(
new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
// TODO Handle item click
// productList is the arraylist used in product list
Products product = productList.get(position);
Contents c = new Contents();
c.setTitle(product.getName());
c.setQuantity(product.getQuantity());
orderList.add(c);
recyclerListAdapter.notifyDataSetChanged();
}
})
);
Here's the adapter for check list,
private List<Contents> contentsList;
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView title;
public TextView quantity;
public MyViewHolder(View view) {
super(view);
title = (TextView) view.findViewById(R.id.txtTitle);
quantity = (TextView) view.findViewById(R.id.txtQuantity);
}
}
public RecyclerListAdapter(List<Contents> contentsList) {
this.contentsList = contentsList;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_product, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
Contents contents = contentsList.get(position);
holder.title.setText(contents.getTitle());
holder.quantity.setText("1");
}
@Override
public int getItemCount() {
return contentsList.size();
}