0

I tried to change the ImageButton background (like in Twitter app ) but if I change the ImageButton in first row then in some other row the ImageButton will also be changed.

And also I need to keep the changed ImageButton background in multiple rows as it is.

And I refered this link

RecyclerView causes issue when recycling

But in the above link solution is there for :

  1. To select only one row at a time (As in Navigation drawer ).

  2. And the other solution will cause the problem I mentioned.

Thanks in advance

Community
  • 1
  • 1
Chat
  • 41
  • 1
  • 6
  • 2
    You have to store the button state somewhere for each of your item. And then in `onBindViewHolder()` set the appropriate background for the button. If you show your adapter code it would be easier to help with the code. – RustamG Oct 06 '16 at 07:13
  • learn how RecyclerView works, you have to keep state of your view in your model. – droidev Oct 06 '16 at 07:18

1 Answers1

0

Here you can find a clear and fast example about recycler view. Say that you should work on onBindViewHolder overrided function.

Store image information and then apply it every time onBindViewHolder is triggered.

 @Override
public void onBindViewHolder(ContactsAdapter.ViewHolder viewHolder, int position) {

    Object yourItem = items.get(position);

    ImageView yourImageView = viewHolder.yourImageView ;

    if(yourItem.containsDifferentImage()){
       yourImageViewsetImageResource(R.drawable.my_new_image);
    }
    else{
       yourImageViewsetImageResource(R.drawable.my_standard_image);
    }

}
Alessandro Verona
  • 1,157
  • 9
  • 23