0

I am using ItemTouchListener from my fragment to access my recyclerview items and clicks but It requires me to click twice to actually trigger a clicklistener..

Here is my code :

        fileManagerRecyclerView.addOnItemTouchListener(RecyclerClickListener(requireContext(), fileManagerRecyclerView, object : RecyclerClickListener.OnItemClickListener {
            override fun onItemClick(view: View, position: Int) {
                currentItemPosition = position
                val thumbnail = view.findViewById<ImageView>(R.id.thumbnail)
                thumbnail.setOnClickListener {
                    showPopupMenu(view, position)
                }
            }

            override fun onItemLongClick(view: View?, position: Int) {

            }
        }))
Dragon
  • 11
  • 1
  • Your `addOnItemTouchListener` sets clicklistener on another view - `thumbnail` , and then `setOnClickListener` opens the popup. Why can't you just set click on `thumbnail`? – Nitish Jan 17 '22 at 09:33
  • You can look at this example on how to implement item click on recylerview properly - [recyclerview-item-click-listener-the-right-way-](https://medium.com/android-gate/recyclerview-item-click-listener-the-right-way-daecc838fbb9) – Nitish Jan 17 '22 at 09:35
  • @Nitish I am trying to implement multiple setonclick, such as thumbnail, menu dot. – Dragon Jan 17 '22 at 09:38
  • Add your showPopupMenu function as parametr to your adapter and invoke her from your viewHolder – rost Jan 17 '22 at 09:45
  • @rost is there any proper way, I can handle it from my fragment, else I will have changes alot of things. – Dragon Jan 17 '22 at 10:11
  • I'm a bit confused here , `as thumbnail, menu dot.` - are these the views in your recycler view , and you want to set onClick on each view differently. if yes, setonCLick in your viewHolder and give a callback to your fragment using interface. Look at this exmaple - [recyclerview item click listener](https://stackoverflow.com/questions/49969278/recyclerview-item-click-listener-the-right-way) – Nitish Jan 17 '22 at 11:40

0 Answers0