2

In my Recyclerview I have a list of items. When I click and hold, I want to display a Dialog and dismiss it when I release it. When I just click on the button I want to open a new Activity. With the code below I have 2 problems:

1 - If I click and hold the button, Activity opens.

2 - If I click and hold the button, and slide my finger down the Dialog is not dismissed.

        itemView.setOnClickListener {
            openActivity()
        }

        itemView.setOnTouchListener { v, event ->
            when(event.action){
                MotionEvent.ACTION_DOWN -> {
                    openDialog()
                    return@setOnTouchListener false
                }
                MotionEvent.ACTION_UP -> {
                    dismissDialog()
                    v.performClick()
                    return@setOnTouchListener false
                }
                else-> {
                    return@setOnTouchListener false
                }
            }
        }

How to solve this problem?

Vitor Ferreira
  • 1,075
  • 1
  • 14
  • 28
  • This might not be an exact duplicate but i think taking a look at [this question](https://stackoverflow.com/questions/26524003/passing-motionevents-from-recyclerview-onitemtouchlistener-to-gesturedetectorcom) will help you solve your problem – Jameido May 05 '21 at 16:51
  • 1
    Ah...this one's tricky. For 2 you just need to handle `ACTION_CANCEL`. 1 is a bit harder to solve. – Ryan M May 05 '21 at 21:13

0 Answers0