Skip to content

Instantly share code, notes, and snippets.

@sandipsavaliya112
Created June 9, 2020 08:27
Show Gist options
  • Save sandipsavaliya112/e746243a65b54ddf3d15bf19bf18b88e to your computer and use it in GitHub Desktop.
Save sandipsavaliya112/e746243a65b54ddf3d15bf19bf18b88e to your computer and use it in GitHub Desktop.
class Adapter<T : BaseModel>(val items: List<T>, val callback : (GenericVH, T)-> Unit) : RecyclerView.Adapter<Adapter.GenericVH>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GenericVH {
return GenericVH(DataBindingUtil.inflate(LayoutInflater.from(parent.context), viewType, parent, false))
}
override fun getItemCount() = items.size
override fun getItemViewType(position: Int) = items[position].resId
override fun onBindViewHolder(holder: GenericVH, position: Int) = callback.invoke(holder, items[position])
class GenericVH(val binding : ViewDataBinding): RecyclerView.ViewHolder(binding.root)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment