Recyclerview Hazards


There are some cases where you may end up using recyclerview in inappropriate ways that could backfire. The recyclerview may throw exceptions which
may have causes difficult to understand.

Let us take a look at some of these cases. These cases are from actual real world experiences.

Case 1:

Whenever you call dataset.clear() please call adapter.notifyDatasetChanged() immediately.

When you call dataset.clear() the recyclerview remains in an invalid state until you call notifyDatasetChanged(). Using the recyclerview in the invalid state will throw nasty exceptions which might be difficult to understand.

So just remember that whenever you call dataset.clear() you must immediately call adapter.notifyDatasetChanged() on it. Before the recyclerview is used.

Lessons to learn : *

Whenever your dataset changes you should call adapter.notifydatasetChanged() as soon as possible. Before you start to use it.

PS: Please note that this article will be updated as soon as we find more of similar cases.

Image Credits :

Cover Image Source :

Leave a Reply

Your email address will not be published. Required fields are marked *