From the Docs - https://developer.android.com/develop/ui/views/touch-and-input/gestures/multi
Use the getActionIndex() function with ACTION_POINTER_UP and ACTION_POINTER_DOWN events only. Don't use this function with ACTION_MOVE events, as this always returns 0.
So, How can I handle the
The current code, not working.
override fun onTouchEvent(event: MotionEvent): Boolean {
when (event.action and MotionEvent.ACTION_MASK) {
MotionEvent.ACTION_MOVE -> {
val pointerId = event.getPointerId(event.actionIndex)
val eventX = event.getX(event.actionIndex).toInt()
val eventY = event.getY(event.actionIndex).toInt()
return true
}
}
return super.onTouchEvent(event)
}
event.actionIndex always returns 0 as mentioned in the Docs and so I am able to handle only the movement of the first touch when there are multiple touches.
As the docs say - use the down an up events to save the pointer ids and then use them in the move event to get the coordinates.
https://developer.android.com/develop/ui/views/touch-and-input/gestures/multi#keep-track-of-pointers