How does one go about detecting a secondary/non-primary finger moving?

There is:

ACTION_DOWN and ACTION_UP to detect a primary finger pressing the screen / leaving the screen

ACTION_POINTER_DOWN and ACTION_POINTER_UP for subsequent fingers pressing / leaving the screen

But there is no ACTION_POINTER_MOVE for monitoring and responding to subsequent fingers moving.

Also, if I log event.getActionIndex(); it always returns '0' regardless of how many fingers are touching the screen (I'm guessing because *ACTION_MOVE* is only interested in the primary finger). So how is it possible test the subsequent fingers?


case MotionEvent.ACTION_MOVE:{  
         int pointerId = event.getPointerId(pointerIndex);  

        //Finger slid to left button so set sprite left  
            if (event.getY(pointerIndex)>=renderer.leftButton("top") && event.getX(pointerIndex)<=renderer.leftButton("right")){  
                renderer.setSpriteState('l', true);  
                renderer.setSpriteState('r', false);  


            //Finger slide to the right button so set sprite right  
                if (event.getY(pointerIndex)>=renderer.rightButton("top") && event.getX(pointerIndex)>renderer.rightButton("left") && event.getX(pointerIndex)<=renderer.rightButton("right")){  
                    renderer.setSpriteState('l', false);  
                    renderer.setSpriteState('r', true);  


The ACTION_MOVE event provides data for multiple fingers.

You can use event.getPointerCount() to find out how many fingers are touching the screen. Then you can loop through the pointers to get data for each one.


case MotionEvent.ACTION_MOVE:
    int count = event.getPointerCount();
    for (int i = 0; i < count; i++) {
        x[i] = event.getX(i);
        y[i] = event.getY(i);

This will give you the x and y values for all of the different touch events.

| improve this answer | |
  • \$\begingroup\$ Hi @IanMarkowitz I've just implemented this it does work, but how can I know which is where? What I mean is this, if I have 2 fingers on the screen and I want to perform an action when finger1 moves from area a to area b (or vice-versa) but not while it's moving within area a (or area b) - how do I do this? I assume I would need to save the positions of each of the fingers that are pressed but I have no way of knowing which is where? If you see what I mean. \$\endgroup\$ – BungleBonce May 28 '13 at 0:02
  • \$\begingroup\$ Actually, you've answered my question - so thanks! I will as a separate one for my question above :-) \$\endgroup\$ – BungleBonce May 28 '13 at 0:05
  • \$\begingroup\$ I've asked the new question, would be grateful if you could have a look - thanks. \$\endgroup\$ – BungleBonce May 28 '13 at 0:36
  • \$\begingroup\$ You can use event.getPointerID(i) to get an identifier for each pointer. To keep track of a finger, you can save the ID on a down action, and check any new move actions against the saved id. \$\endgroup\$ – Ian Markowitz May 28 '13 at 1:12
  • \$\begingroup\$ take a look at developer.android.com/training/gestures/multi.html \$\endgroup\$ – Ian Markowitz May 28 '13 at 1:13

You can get the effective pointer index of moving finger by checking which pointer changed:

private final int MAX_POINTER = 5; // 5 different touch pointers supported on most devices
private float mLastTouchPositionX[];
private float mLastTouchPositionY[];

public boolean onTouchEvent(MotionEvent aEvent)
int tActionIndex = aEvent.getActionIndex();
int tPointerCount = aEvent.getPointerCount();
     * Check which pointer changed on move
    if (tMaskedAction == MotionEvent.ACTION_MOVE) {
        for (int i = 0; i < tPointerCount && i < MAX_POINTER; i++) {
            if (mLastTouchPositionX[i] != aEvent.getX(i) || mLastTouchPositionY[i] != aEvent.getY(i)) {
                mLastTouchPositionX[i] = aEvent.getX(i);
                mLastTouchPositionY[i] = aEvent.getY(i);
                // Found new action index
                tActionIndex = i;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.