3

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));
            }
yogesh lokhande
  • 1,245
  • 1
  • 11
  • 20
Vanraj Ghed
  • 1,261
  • 11
  • 23

3 Answers3

2

Instead of changing color on feetInt maintain a flag in your object class and on the basis of particular flag change your background color

yogesh lokhande
  • 1,245
  • 1
  • 11
  • 20
0

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.

Pang
  • 9,564
  • 146
  • 81
  • 122
Rishabh Saxena
  • 1,765
  • 15
  • 26
0
holder.setIsRecyclable(false);
barbsan
  • 3,418
  • 11
  • 21
  • 28
  • It will be great if you could explain your solution and how it solves the OP's problem – ammportal Jul 04 '19 at 10:12
  • RecyclerView uses one view multiple times. user Scroll the list then remaining off screen item will display. for stop the Recycle item you can use setIsRecyclable(false) – sanjay sawan Jul 04 '19 at 10:25
  • If you read the question though, the OP does not want to use this specific property – ammportal Jul 04 '19 at 10:28