0

I have a WebView in my RecyclerView, whenever I call RecyclerView.notifyDataSetChanged the WebView will have a short flashing.

I don't want any changes happen on the WebView, how can I do this ?

I know I can solve this with using notifyItemXXX instead of notifyDataSetChanged. But I do need notifyDataSetChanged method.

L. Swifter
  • 3,179
  • 28
  • 52
  • Can you keep track of the webView index and use notifyItemRangeChanged? – Alok Omkar Jul 28 '16 at 05:57
  • @AlokOmkar I can keep the `WebView`'s trace, but the `notifyDataSetChanged` is the simplest way to refresh the dataset. If I use `notifyItemRangeChanged`, I need to do a lot of work on my app's logic. – L. Swifter Jul 28 '16 at 07:40
  • To prevent flashing effect, check out this SO Answer : http://stackoverflow.com/a/32488059/2648035 - let me know if it helps – Alok Omkar Jul 29 '16 at 11:35

1 Answers1

0

As the notifyDataSetChanged() official doc says "LayoutManagers will be forced to fully rebind and relayout all visible views.". So I think the webview's flash is caused by this. And you can find this "Rely onnotifyDataSetChanged() as a last resort.". As you mentioned you must use this method, so can you please give more info so I can help you to find out a better solution.

Beck
  • 77
  • 5
  • It seems that If I use `notifyDataSetChanged`, the `webView` must flash. I need `notifyDataSetChanged` because it's the simplest way to refresh the dataset. My `RecyclerView` includes a lot of different types of entries, after a response from the server, some need to be deleted, some need to be added in, some need to refresh and some do nothing. Really hard to use `notifyItemXXX`. – L. Swifter Jul 28 '16 at 07:48
  • An other question, can I use both `notifyItemRangeRemoved` and `notifyItemRangeChanged` at the same time ? – L. Swifter Jul 28 '16 at 07:49
  • 1
    Yes, you can use `notifyItemRangeRemoved` and `notifyItemRangeChanged` at the same time, but be careful about the range. As the `notifyItemRangeRemoved` says " The items previously located at and after positionStart + itemCount may now be found at oldPosition - itemCount." – Beck Jul 28 '16 at 08:16
  • There seems to be no other way, I will use `notifyItemRangeXXX` to do this. Thanks for your answer, and I will accept it. – L. Swifter Jul 29 '16 at 01:51