Created
May 30, 2021 23:15
-
-
Save k0siara/d85aa5c6cf9cdd1bf9548a1c8264552e to your computer and use it in GitHub Desktop.
CustomListAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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