There is a RecycleView with an item of different goods, the goods indicate the quantity of the goods and the price. I made the counter in the adapter, when you press the button, the quantity of one product increases or decreases and the price, respectively. and all at once, and the value of the price increases only 1 time and also for all goods at once.
public class MyAdapterProducts extends RecyclerView.Adapter<MyViewHolderProducts> { Context c; ArrayList<Product> products; String jsonURL2; int price2, price3; RequestQueue requestQueue; public MyAdapterProducts(Context c, ArrayList<Product> products) { this.c = c; this.products = products; } @Override public MyViewHolderProducts onCreateViewHolder(ViewGroup parent, int viewType) { View v = LayoutInflater.from(c).inflate(R.layout.model_products, parent, false); return new MyViewHolderProducts(v); } @Override public void onBindViewHolder(final MyViewHolderProducts holder, int position) { Product product = products.get(position); final String name = product.getName(); final String anons = product.getAnons(); final String price = product.getPrice(); final String product_id = product.getId(); final String image = product.getImg_url(); holder.nameTxt.setText(name); holder.anonsTxt.setText(anons); holder.priceTxt.setText(price + " " + "тг."); //Textview цены holder.idTxt.setText(product_id); holder.increase.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int counter = 1; holder.showValue.setText(Integer.toString(counter)); //Textview значения счетчика price2 = Integer.parseInt(price); price3 = Integer.parseInt(price); counter++; price2 = price2 + price3; holder.priceTxt.setText(String.valueOf(price2) + " " + "тг."); holder.showValue.setText(Integer.toString(counter)); } }); holder.decrease.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int counter = 1; // holder.showValue.setText(Integer.toString(counter)); //counter = count; if (counter > 1) { counter--; price2 = price2 - price3; holder.priceTxt.setText(String.valueOf(price2) + " " + "тг."); holder.showValue.setText(Integer.toString(counter)); } } });