The question is the following: I have a RecyclerView list, where there is a button next to each item (with a picture). When you press a button, the image changes. I need to save the state of the button (and the picture itself), if the person pressed the button, and so that after exiting the Activity and returning back, the button remains in the state in which it was before the exit. What are the ways and solutions to this issue?
This is how I change the picture and the state of the button:
In ViewHolder I specified the boolean variable, which I set to false , and then used it in OnBindViewHolder .
public void onBindViewHolder(@NonNull final ProductViewHolder holder, final int position) { holder.textProduct.setText(list.get(position).getProductName()); holder.btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(holder.click==false) { MainMenuActivity.basketList.add(list.get(position).getProductName()); holder.btn.setBackgroundResource(R.drawable.delete); holder.click=true; } else { holder.btn.setBackgroundResource(R.drawable.plus); holder.click=false; MainMenuActivity.basketList.remove(list.get(position).getProductName()); } } }); }