i'm writing an Android app for a school project that performs a different action depending on how many fingers the user taps the screen with.
Right now this action is just to display the number of pointers detected as a toast.
I'm using the getPointerCount() method, but for some reason, I get multiple toasts. For example, a three finger tap gives me toasts for two and three finger taps, a four finger tap will give me toasts for two, three and four finger taps, and so on.
I cannot for the life of me figure out why this is. A four finger tap should display ONE toast saying "4", not cycle through 2, 3 and 4! Any help would be greatly appreciated.
public boolean onTouchEvent(MotionEvent event)
{
int action = event.getAction();
switch(action & MotionEvent.ACTION_MASK)
{
case MotionEvent.ACTION_POINTER_DOWN:
int count = event.getPointerCount();
if (count == 2) {
finish();
}
else if (count == 4) {
Toast.makeText(this, String.valueOf(count), Toast.LENGTH_SHORT).show();
}
else if (count == 3) {
Toast.makeText(this, String.valueOf(count), Toast.LENGTH_SHORT).show();
}
break;
}
return true;
}
P.S, I have tried moving the code outside of the switch statement, and bizarrely , this causes the toasts to count up AND down!