[英]Recyclerview calls notifyItemChanged to cause a blank item
RecyclerView
calls notifyItemChanged()
to cause a blank entry RecyclerView
调用notifyItemChanged()
导致空白条目
I have a RecyclerView
and it's every child item has a RecyclerView
, when the dataset of RecyclerView
in child item has changed (eg.some item inserted). 我有一个RecyclerView
和它的每一个子项目有RecyclerView
,当数据集RecyclerView
在子项已经改变(eg.some项目插入)。 I try to call the parent RecyclerView
's notifyItemChanged()
to refresh it. 我尝试调用父RecyclerView
的notifyItemChanged()
刷新它。 But when I call that function, it will cause a blank item below. 但是,当我调用该函数时,它将导致下面的空白项。
mMessagesAdapter.notifyItemChanged(position);
when I call notifyItemChanged()
for a position, there will be a blank item below, it can be visible, but there is no data, and it's all white. 当我为某个位置调用notifyItemChanged()
,下面将有一个空白项目,它是可见的,但是没有数据,并且全为白色。
Demo: https://github.com/zoodeveloper/NestBug 演示: https : //github.com/zoodeveloper/NestBug
The adapter.notifyItemChanged
() is used for refreshing an existing item. adapter.notifyItemChanged
()用于刷新现有项目。 If you are adding a new item, then you should call adapter.notifyItemRangeChanged(position, data.size())
如果要添加新项目,则应调用adapter.notifyItemRangeChanged(position, data.size())
If you are inserting a new item you can use notifyItemInserted (int position)
如果要插入新项目,则可以使用notifyItemInserted (int position)
It is used to notify any registered observers that the item reflected at position has been newly inserted. 它用于通知任何注册的观察者该位置反射的项目已被新插入。 The item previously at position is now at position position + 1. 先前在该位置的项目现在在位置位置+1。
Maybe you should consider to call adapter.notifyItemChanged() from the main thread. 也许您应该考虑从主线程调用adapter.notifyItemChanged()。
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = new Runnable() {
@Override
public void run() { adapter.notifyItemChanged() }
};
mainHandler.post(myRunnable);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.