I\'m trying to update a ViewHolder
in a RecyclerView
without rebinding the entire thing. According to the docs, I should do this by calling R
If you use item animator (by default it's enabled) then payload will be always empty. Look at this answer in android issue tracker:
This is how payload is designed the work. It is only passed to on bind "if we are rebinding to the same view holder". Same for data binding, if you are not binding to the same view holder, you cannot do the bind incrementally. In case of change animations, RV creates two copies of the View to crossfade so you are not binding to the same VH in postLayout.
Soon, we'll provide an API to run change animations within the same ViewHolder.
Therefore, until they share this new API we need to use something like this:
mRecyclerView.setItemAnimator(null);
edit: See @blindOSX comment, where he noticed that to enable payloads you can only disable animations of item change events.
edit2: Looks like they've updated this behaviour without notice about it. See updated @Patricia Li answer.