Vitali Pom
Vitali Pom

Reputation: 602

Android multitouch - ignore one finger

GestureDetector has methods for a single finger, as well as for multiple fingers. How can I ignore one finger when there are few fingers on the screen and pass to it only a single finger?

Upvotes: 0

Views: 522

Answers (1)

orenk86
orenk86

Reputation: 729

I doubt you can do this... Gesture detectors are supposed to listen to a pre-defined touch/motion event. If there are too many fingers on the screen, the pre-defined gesture won't happen...

You can, however, track regular multi-touch events and follow only, say, the first finger that touched the screen. You can see a detailed explanation in the docs here.

Once a few fingers touch the screen, the generated MotionEvent will contain individual pointers to each one:

private int mActivePointerId;

public boolean onTouchEvent(MotionEvent event) {
    ....
    // Get the pointer ID
    mActivePointerId = event.getPointerId(0);

    // ... Many touch events later...

    // Use the pointer ID to find the index of the active pointer 
    // and fetch its position
    int pointerIndex = event.findPointerIndex(mActivePointerId);
    // Get the pointer's current position
    float x = event.getX(pointerIndex);
    float y = event.getY(pointerIndex);
}

Upvotes: 1

Related Questions