Recycled Recyclerview Item Keeps The Old Background Color
I have a recycler view and inside the onClick(View view) i'm changing the background color to almost transparent red view.setBackgroundColor(Color.argb(64, 183, 28, 28)); but somet
Solution 1:
The simplest way to achieve this in my opinion is to give each item in your RecyclerView a state (boolean) and set the background depending on the state. This way when you recycle the view, the correct background is drawn.
if(isClicked){
itemView.setBackgroundColor(Color.RED);
}
else{
itemView.setBackgroudnColor(Color.WHITE);
}
Solution 2:
You should set all attributes in your onBindViewHolder()
, because, as you can see, view may not be fresh but recycled and show state of previously presented record. So if background color maters, you must set it too in onBindViewHolder()
.
Post a Comment for "Recycled Recyclerview Item Keeps The Old Background Color"