问题
So, I've got a RecyclerView
with some textviews on the cards. One of these can turn red&bold, based on some parameters, using holder.DeviceTV.setTextColor(Color.RED);
& holder.DeviceTV.setTypeface(null, Typeface.BOLD);
This works perfectly fine, as you can see in the image below, above the black bar.
Later, I remove all the cards with the red&bold textview, and notify the adapter. This results in what you see below the black bar in the image, which should NOT be the case. I'm guessing this is because (duh) this is a RecyclerView
, so the parameters I set on it before, have stayed around. I don't know why it chooses to use the cards with the red&bold text, but it does, every time.
What is the best way to fix this issue?

回答1:
You would need to call holder.DeviceTV.setTextColor(Color.BLACK)
and holder.DeviceTV.setTypeface(null);
in the onBindViewHolder method to make sure everything is displayed as you want.
There might be a small overhead to that but it's definitely much faster than creating a new View from scratch.
来源:https://stackoverflow.com/questions/36779656/recyclerview-parameters-stick-around-after-re-drawing-the-list