Skip to content

Instantly share code, notes, and snippets.

@tfcporciuncula
Created January 14, 2019 14:30
Show Gist options
  • Save tfcporciuncula/64ac3373bb60aa3f5eab7c608737ae5e to your computer and use it in GitHub Desktop.
Save tfcporciuncula/64ac3373bb60aa3f5eab7c608737ae5e to your computer and use it in GitHub Desktop.
DataBindingAdapter
abstract class DataBindingAdapter<T>(diffCallback: DiffUtil.ItemCallback<T>) :
ListAdapter<T, DataBindingViewHolder<T>>(diffCallback) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DataBindingViewHolder<T> {
val layoutInflater = LayoutInflater.from(parent.context)
val binding = DataBindingUtil.inflate<ViewDataBinding>(layoutInflater, viewType, parent, false)
return DataBindingViewHolder(binding)
}
override fun onBindViewHolder(holder: DataBindingViewHolder<T>, position: Int) = holder.bind(getItem(position))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment