简体   繁体   English

如何将子点击监听器添加到任何子项目 manneohlund smart-recycler-adapter

[英]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.

相关问题 如何将单击侦听器添加到 Recycler View 的子级? - How can i Add the click listeners to the child of Recycler View? 滚动时如何使用回收者视图识别节适配器的子项的位置 - How to identify the position of child item of section adapter using recycler view while scrolling 如何为回收器适配器提供点击监听接口的实现? - How to provide an implementation of the click listener interface for the recycler adapter? 如何使用CardView Item在`RecyclerView.Adapter&#39;中单击侦听器 - How to add an Item Click Listener in `RecyclerView.Adapter' using CardView Item 如何为列表视图适配器中的开关添加点击监听器 - how to add click listener for a switch in listview adapter 在项目上,单击“回收者”视图的侦听器以显示图像 - On item Click Listener of Recycler view to show Image 如何在回收器适配器中初始化侦听器? - How do I initialize a listener in a recycler adapter? 将侦听器传递给回收器适配器 - Passing a listener to a recycler adapter 当适配器上的项目非零时,Firebase 添加新子项 - Firebase add new child when an item on adapter is non-zero 从父recycleview适配器android在子recycleview中添加项目 - Add item in child recycleview from parent recycleview adapter android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM