question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Improve]Do not use notifyDataSetChanged() in setNewData.

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
dyguestscommented, May 19, 2017

话说我为啥不用中文???

总之通过 notifyItemRangeChanged(start,count)来更新的itemView时不会闪。 而用 notifyDataSetChanged()来更新的itemView都会闪一下啊。OTL。

0reactions
dyguestscommented, May 24, 2017

Www,sorry,没考虑header的情况,暂时没啥好的解决办法。😦

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found