To properly implement a DiffUtil.ItemCallback<T>
passed inside the constructor of ListAdapter, both areItemsTheSame
and areContentsTheSame
must be implemented.
Now for areItemsTheSame
it is advised that a unique identifier of type of . So for my case where is a data class without a deducible unique identifier, how am I supposed to implement it properly? When simply doing oldItem == newItem
in both functions, I obviously get a flashing animation on the item since it thinks it's a completely different item since areItemsTheSame
returned false.
So how do people fix this properly? Would returning true
anyway if the data type is the same which would then trigger the areContentsTheSame
be a fix? And if not, why? If I do that currently, the recycler properly understands that just some data has changed, and only the necessary parts of the view "flash" with the new data.