Reputation: 1271
I want to change Recyclerview
item background color on my condition but when I scroll background color automatically changed I know holder.setIsRecyclable(false);
but I don't want to set holder.setIsRecyclable(false);
and I know
if(item.value == 1){
// do something
} else{
// do something
}
but i want to do using nested if else
if (feetInt > 0 && feetInt < 4) {
((PatientViewHolder) holder).rlClientItemMain.setBackgroundColor(ContextCompat.getColor(mContext, R.color.player_list_green));
} else if (feetInt >= 4 && feetInt < 6) {
((PatientViewHolder) holder).rlClientItemMain.setBackgroundColor(ContextCompat.getColor(mContext, R.color.player_list_yellow));
} else if (feetInt == 0 || feetInt >= 6) {
((PatientViewHolder) holder).rlClientItemMain.setBackgroundColor(ContextCompat.getColor(mContext, R.color.player_list_red));
}else{
((PatientViewHolder) holder).rlClientItemMain.setBackgroundColor(ContextCompat.getColor(mContext, R.color.player_list_grey));
}
Upvotes: 3
Views: 1470
Reputation: 1795
It looks like you are not updating the value of feetInt for every single object in list. That's why you are facing this issue.
Update feet int value in list for different different position, you will get the desire result.
Also, remove getItemViewCount() and setIsRecyclable(). These are not required at all. Also, share your code for more specific answers.
Upvotes: 0
Reputation: 1275
Instead of changing color on feetInt
maintain a flag in your object class and on the basis of particular flag change your background color
Upvotes: 2