Skip to content

Instantly share code, notes, and snippets.

@k0siara
Created May 30, 2021 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k0siara/d85aa5c6cf9cdd1bf9548a1c8264552e to your computer and use it in GitHub Desktop.
Save k0siara/d85aa5c6cf9cdd1bf9548a1c8264552e to your computer and use it in GitHub Desktop.
CustomListAdapter.kt
class CustomAdapter : ListAdapter<Item, ItemViewHolder>(DiffUtilCallback) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SpotViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item, parent, false)
return ItemViewHolder(view)
}
override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
holder.bind(currentList[position])
}
object DiffUtilCallback : DiffUtil.ItemCallback() {
override fun areItemsTheSame(oldItem: Item, newItem: Item) = oldItem.id == newItem.id
override fun areContentsTheSame(oldItem: Item, newItem: Item) = oldItem == newItem
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment