3

So, I am trying to check multiple screen touches with an onTouchEvent, but it still only seems to read the first touch. Can anyone help? Here is my code:

public boolean onTouchEvent(MotionEvent e)
{
    int num = e.getPointerCount();
    for(int a = 0;a<num;a++)
    {
    int x = (int) e.getX(e.getPointerId(a));
    int y = (int) e.getY(e.getPointerId(a));
    check(x,y);
    }

    return false;
}

I looked over a lot of these forums, but most of the multi touch related topics were about zooming.

2 Answers 2

4

Your code works well on my device (Nexus S, Android 2.3). It reads all touches.

Here is the test code:

  public boolean onTouchEvent(MotionEvent e) {
    int num = e.getPointerCount();
    for (int a = 0; a < num; a++) {
      int x = (int) e.getX(e.getPointerId(a));
      int y = (int) e.getY(e.getPointerId(a));
      Log.d(TAG, "pointer_" + e.getPointerId(a) + ": x = " + x
          + ", y = " + y);
    }
    return false;
  }

Here is the log (touch with 5 fingers):

11-09 17:32:55.542: D/Touch(20594): pointer_0: x = 169, y = 613
11-09 17:32:55.542: D/Touch(20594): pointer_1: x = 407, y = 289
11-09 17:32:55.542: D/Touch(20594): pointer_2: x = 62, y = 441
11-09 17:32:55.542: D/Touch(20594): pointer_3: x = 251, y = 202
11-09 17:32:55.542: D/Touch(20594): pointer_4: x = 132, y = 256

What is your Android device and OS version?

Sign up to request clarification or add additional context in comments.

3 Comments

I have an evo 4g on Cyanogen 7.1, so i think android 2.3.
Nevermind, everything is working now. For some reason, it would not detect the new touches if I returned false. When i changed the return to true, everything worked. Thanks
My app crashes when i execute the code. Error is here: pastebin.com/3L35DWFZ
0

This happens because your method will return false when you want to make move. All multi finger actions should return true.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.