MotionEvent's ACTION_UP could not work after ACTION_DOWN evet

141 Views Asked by At

I tried to users while to pressed button, run handler, then release button, finish it. But MotionEvent.ACTION_UP could not work like this below code, then my runnable infinite loop continue. How can I triggered ?

myButton.setOnTouchListener{view, event->
when(event.action){
  MotionEvent.ACTION_DOWN -> {myhandler.post{myrunnableaction} true}
  MotionEvent.ACTION_UP -> { myhandler.removeCallbacks(myrunnableaction) true}
}
view.onTouchEvent(event) ?: true
}
 ``
1

There are 1 best solutions below

0
Pavel Erokhin On

removeCallbacks method removes you Runnable from message queue, when your Runnable already launched you can't remove that with removeCallbacks method because already launched.