Skip to content

Instantly share code, notes, and snippets.

@ananth10
Created March 16, 2023 12:24
Show Gist options
  • Save ananth10/bb4f2d8e7a95f4fd2bf0b11ea0b307b8 to your computer and use it in GitHub Desktop.
Save ananth10/bb4f2d8e7a95f4fd2bf0b11ea0b307b8 to your computer and use it in GitHub Desktop.
How To Use DiffUtil In RecyclerView Adapter
private val diffUtil = object : DiffUtil.ItemCallback<String>() {
override fun areItemsTheSame(oldItem: String, newItem: String): Boolean {
return oldItem == newItem
}
override fun areContentsTheSame(oldItem: String, newItem: String): Boolean {
return oldItem == newItem
}
}
private val recyclerListDiff = AsyncListDiffer(this, diffUtil)
var imageList: List<String>
get() = recyclerListDiff.currentList
set(value) = recyclerListDiff.submitList(value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment