android-reactions
android-reactions copied to clipboard
Delegate Touch Event Without lifting the finger
How can I select an item without lifting the finger on a long press? I have implemented the long-press but unable to select items I have to release my finger than only I am able to select the items. Would be great if you can help me.
You can use the below mentioned code in the block of setReactions function, this is the only way to do achieve long press without lifting a finger. reactionBtutton.setOnTouchListener(popup) reactionBtutton.setOnTouchListener { arg0, arg1 -> when (arg1.action) { MotionEvent.ACTION_DOWN -> { timer = Timer() timer.schedule(object : TimerTask() { override fun run() { CoroutineScope( Dispatchers.Main ).launch { popup.onTouch(arg0, arg1) } } }, 300) //time out 1/2s } MotionEvent.ACTION_UP -> { timer.cancel() } else -> false } false }