Created
June 9, 2020 08:27
-
-
Save sandipsavaliya112/e746243a65b54ddf3d15bf19bf18b88e to your computer and use it in GitHub Desktop.
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 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