Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Multi Touch

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.

like image 500
user1036727 Avatar asked Aug 15 '26 18:08

user1036727


1 Answers

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?

like image 186
umbalaconmeogia Avatar answered Aug 17 '26 07:08

umbalaconmeogia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!