[Improve]Do not use notifyDataSetChanged() in setNewData.
See original GitHub issueI saw code notifyDataSetChanged();
in com.chad.library.adapter.base.BaseQuickAdapter#setNewData
.
But,Is that better than use code below???:
int oldSize = list.size();
list.clear();
list.addAll(items);
int newSize = list.size();
if (newSize == oldSize) {
notifyItemRangeChanged(0, oldSize);
} else if (newSize > oldSize) {
notifyItemRangeChanged(0, oldSize);
notifyItemRangeInserted(oldSize, newSize - oldSize);
} else {
notifyItemRangeChanged(0, newSize);
notifyItemRangeRemoved(newSize, oldSize - newSize);
}
Before code:All item will be flickered.
By this way:The item will not be flickered.
And sorry for my poor English. 😃
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
How to update RecyclerView Adapter Data - Stack Overflow
Update the ArrayList from the fragment where recyclerView is created, set new data to adapter, and then call adapter.notifyDataSetChanged() ; it ...
Read more >Updating data in an Android RecyclerView - Suragch - Medium
This can also be an expensive operation, so it is not recommended to use notifyDataSetChanged() if you are only updating a single item...
Read more >Refresh recyclerview after delete item - Terapie Familiari
notifyDataSetChanged() ; it did not work. ... You can delete an item using that menu. the animation is normal, but the index doesn't...
Read more >NotifyDataSetChanged: Invalidating All RecyclerView Data
The RecyclerView adapter's onNotifyDataSetChanged method does not specify what about the data set has changed, forcing any observers to assume that all ...
Read more >Calling NotifyAll to Update RecyclerView from External Method
Am I not allowed to use GetAdapter() (if I am required to keep a local ... NotifyAll() cause a problem and NotifyDataSetChanged() doesn't?...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
话说我为啥不用中文???
总之通过 notifyItemRangeChanged(start,count)来更新的itemView时不会闪。 而用 notifyDataSetChanged()来更新的itemView都会闪一下啊。OTL。
Www,sorry,没考虑header的情况,暂时没啥好的解决办法。😦