Dale_Plante
Dale_Plante

Reputation: 934

Does notifyItemChanged() force a call to onBindViewHolder()?

When I call notifyItemChanged() on my RecyclerView, the corresponding Views (in this case, buttons) do not get updated as expected. The reason I am calling them is that data has changed which would cause their background color to change. Does this mean that notifyItemChanged() doesn't force a call to onBindViewHolder()?

I tried using notifyDataSetChanged() and that DOES cause the views to reload as I want, so I know my implementation is correct. (Note I don't want to use notifyDataSetChanged(), as that is inefficient, I only used it as a sanity test).

Upvotes: 7

Views: 3001

Answers (1)

vishal arote
vishal arote

Reputation: 126

To Refresh your listview Register a new observer to listen for data changes. using registerAdapterDataObserver

The adapter may publish a variety of events describing specific changes. Not all adapters may support all change types and some may fall back to a generic "something changed" event if more specific data is not available.

Components registering observers with an adapter are responsible for unregistering those observers when finished.

Upvotes: 2

Related Questions