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
}
``
removeCallbacksmethod removes youRunnablefrom message queue, when yourRunnablealready launched you can't remove that withremoveCallbacksmethod because already launched.