Android - How to handle two fingers

The documentation says this:

The gesture begins with a motion event with ACTION_DOWN, which ensures that the first down pointer is positioned. Like every additional pointer that goes up or down, the structure generates a motion event with ACTION_POINTER_DOWN or ACTION_POINTER_UP, respectively.

So, I did an override of the onTouchEvent function in my activity:

@Override public boolean onTouchEvent(MotionEvent MEvent) { motionaction = MEvent.getAction(); if(motionaction == MotionEvent.ACTION_DOWN) { System.out.println("DEBUG MESSAGE POINTER1 " + MEvent.getActionIndex() ); } if(motionaction == MotionEvent.ACTION_POINTER_DOWN) { System.out.println("DEBUG MESSAGE POINTER2 " + MEvent.getActionIndex() ); } } 

Unfortunately, the second, if never introduced. The activity contains 2 views with 2 OnTouchListener , I know that onTouchEvent is called only if the activity view does not use the event, so I tried to return false in and this way I can recognize only the first touch of the finger, but this does not allow the listener to receive the event ACTION_UP and does not allow me to recognize the touch of the second finger. I also tried to return true in the listener, but after manually calling the onTouchEvent function, but this allows me to recognize only the first touch of the finger.

What is wrong in my code?

+6
source share
1 answer

I believe that there is no masking operation in your code, for example:

 switch (motionaction & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_POINTER_DOWN: } 

This code should be able to check ACTION_POINTER_DOWN.

Good luck and tell what happens.

Tommy Qui

+15
source

Source: https://habr.com/ru/post/919793/


All Articles