重新绘制列表后,RecyclerView参数仍然存在 [英] RecyclerView parameters stick around after re-drawing the list

查看:39
本文介绍了重新绘制列表后,RecyclerView参数仍然存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我在卡上有一个RecyclerView带有一些文本视图.其中之一可以使用holder.DeviceTV.setTextColor(Color.RED);& holder.DeviceTV.setTypeface(null, Typeface.BOLD);如您在黑色条上方的下图中所见,这可以很好地工作.

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.

稍后,我将所有带有红色和粗体文本视图的卡移除,并通知适配器.这将导致您在图像中的黑条下方看到的内容,但实际情况并非如此.我猜这是因为(duh)这是RecyclerView,所以我之前在它上面设置的参数一直存在.我不知道为什么它选择使用带有红色和粗体字的卡片,但是每次都会这样做.

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?

推荐答案

您需要在

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.

这篇关于重新绘制列表后,RecyclerView参数仍然存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆