Solution 1 :
You can save the scroll position prior to calling submitList()
and then restore it afterwards:
Solution 2 :
Yes, It is possible to update Adapter items in a way that doesn’t refresh the whole list. Suppose you created an adapter and the name of the adapter is “ListAdapter“.If you wanna update the adapter items that means you wanna change the value of a certain position. Here you just pass the position.
listAdapter.notifyItemChanged(position:Int)
Maybe you inserted values in a position,
listAdapter.notifyItemInserted(position:Int)
or you may remove a value from a position,
listAdapter.notifyItemRemoved(position:Int)
Solution 3 :
As ianhanniballake mentioned, I was implementing the DiffUtil
incorrectly. I was checking the whole new and old values in areItemsTheSame
function, while should only check a unique field (like id
).
override fun areItemsTheSame(oldItem: FuelSubsidyEntity, newItem: FuelSubsidyEntity): Boolean {
return oldItem.reportId == newItem.reportId
}
Problem :
Is there any way to update ListAdapter
items in a way that doesn’t refresh the whole list?
For now, if you call adapter.submitList(newITems)
again, it will scroll the list to the top again, not just replacing current items with new ones.
Comments
Comment posted by ianhanniballake
Clearly you have not implemented DiffUtil correctly, otherwise RecyclerView would have kept the topmost visible item with a matching ID visible. Include your class and your DiffUtil implementation.