2

I have notifyDataSetChanged() followed by notifyItemChanged(0, Unit) with payload called for the same adapter, containing, say, 3 items.

Each of the calls is made inside view.post().

I expect onBindViewHolder() will be called 4 times: 3 times for notifyDataSetChanged() and one time for notifyItemChanged()

In fact it is called 3 times, all with empty payload.

But if I replace view.post() on view.postDelayed({notifyItemChanged(0, Unit)}, 1000), everithing works like a charm.

Could you explain me, why this happens?

Alexey
  • 2,980
  • 4
  • 30
  • 53

1 Answers1

0

As it is documented on Google documentation:

Post:post causes the Runnable to be added to the message queue. PostDelayed : Causes the Runnable to be added to the message queue, to be run after the specified amount of time elapses.

In your case, view.post causing runnable to to execute immediately that is why you are facing this behaviour while in case of postDelayed it is taking mentioned time by using time recycler view has enough time to recyle or update items accordingly.

Abdul Waheed
  • 4,540
  • 6
  • 35
  • 58