RecyclerView parameters stick around after re-drawing the list

风格不统一 提交于 2019-12-20 06:26:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!