Last active
August 3, 2022 21:03
-
-
Save Kashif-E/e3edce66cc3dd6af4ec13b1f5e53bbeb 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
import android.view.ViewGroup | |
import androidx.recyclerview.widget.RecyclerView | |
import androidx.viewbinding.ViewBinding | |
abstract class MyBaseAdapter(): | |
RecyclerView.Adapter<MyBaseAdapter.MyBaseViewHolder>() { | |
inner class MyBaseViewHolder(private val itemViewBinding: ViewBinding) : | |
RecyclerView.ViewHolder(itemViewBinding.root) { | |
fun bindView(binder: (binding: ViewBinding) -> Unit) { | |
binder(itemViewBinding) | |
} | |
} | |
open var viewBinder: ((ViewGroup) -> ViewBinding)? = null | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyBaseViewHolder { | |
return viewBinder?.let { | |
it(parent) | |
}?.let { | |
MyBaseViewHolder(it) | |
}!! | |
} | |
override fun getItemCount(): Int { | |
return getCount() | |
} | |
abstract fun getCount():Int | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment