Search code examples
javaandroidandroid-recyclerviewopen-source

RecyclerView source code has empty onChange method


I'm wondering what does notifyDataSetChanged() actually do. I was trying to navigate source code so I found it calling notifyChanged() method in a static member class that called AdapterDataObservable

notifyChanged() loops through data and call onChange() which is empty body.

So I can see nothing notifyDataSetChanged() did, how does my view change?


Solution

  • A method setAdapterInternal() is called when either setAdapter or swapAdapter are called, and it actually registers your RecyclerView as observer of changes in the adapter.

    The data changes in your adapter, the adapter is the one responsible for watching your dataset, and it just let's the view know when the data changes, to adjust it's layout or bounds or whatever is needed to account for the data changes.