I am using this library for general adapter -> Smart-Recycler-Adapter
This is my code
SmartRecyclerAdapter
.items(listItems)
.map(Header::class, HeaderViewHolder::class)
.map(KeyVal::class, KeyValViewHolder::class)
.map(KeyLink::class, KeyLinkViewHolder::class)
.map(Picture::class, PictureViewHolder::class)
.add(StickyHeaderItemDecorationExtension(
headerItemType = Header::class
))
.add(OnCustomViewEventListener { event ->
showToast(event)
})
.into<SmartRecyclerAdapter>(binding.recyclerview)
I am able to add click listener to the whole item of recyclerview. But I want to add click listener on a child view of one of my view-holder. I have done this many times on my own custom adapters but I don't know how to add this functionality by using this library. Thankyou
You can add listeners to the itemView (View of the particular item of the list) in the respective Viewholders.
For example, in your PictureViewHolder class, you must have an instance of view which represents the view of the individual item of the list. You can just set on click listener to this view, and do whatever you wish to perform on click.
For instance, if you Viewholder class looks something like this
inner class PictureViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
fun bind(item: PictureClass) {
itemView.setOnClickListener {
// Do something
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.