Skip to content

Instantly share code, notes, and snippets.

Last active January 4, 2022 13:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Generic Base Recyclerview Adapter with ViewBinding & Multiple View Click Support
abstract class BaseRecyclerAdapter<T : BaseComparable, VB : ViewBinding>(
private inline val bindingInflater: (LayoutInflater, ViewGroup, Boolean) -> VB,
private inline val onBind: (item: T, binding: VB) -> Unit,
private inline val actions: (VB) -> List<Pair<View, (T) -> Unit>>,
) : ListAdapter<T, BaseRecyclerAdapter<T, VB>.BaseViewHolder>(BaseDiffCallback<T>()) {
inner class BaseViewHolder(
val binding: VB
) : RecyclerView.ViewHolder(binding.root) {
init {
actions(binding).forEach { actionPair ->
actionPair.first.setOnClickListener {
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): BaseRecyclerAdapter<T, VB>.BaseViewHolder {
val binding = bindingInflater(
return BaseViewHolder(binding)
override fun onBindViewHolder(
holder: BaseRecyclerAdapter<T, VB>.BaseViewHolder,
position: Int
) {
onBind.invoke(currentList[position], holder.binding)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment