[英]How to add child click listener to any child item manneohlund smart-recycler-adapter
I am using this library for general adapter -> Smart-Recycler-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.我可以将点击监听器添加到整个 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.您可以在相应的 Viewholders 中向 itemView(列表中特定项目的视图)添加侦听器。
For example, in your PictureViewHolder class, you must have an instance of view which represents the view of the individual item of the list.例如,在您的 PictureViewHolder class 中,您必须有一个视图实例,它代表列表中单个项目的视图。 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例如,如果您的 Viewholder class 看起来像这样
inner class PictureViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
fun bind(item: PictureClass) {
itemView.setOnClickListener {
// Do something
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.