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.
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?
ignacio pugliese
This happens because your method will return false
when you want to make move. All multi finger actions should return true
.
来源:https://stackoverflow.com/questions/8059127/android-multi-touch