Search code examples
androidmulti-touch

Multitouch seems not to work on all 3 devices which I have tested


Can somebody tell me why I ALWAYS get "1" from :

 public boolean onTouchEvent(MotionEvent event) {
      int i = event.getPointerCount();
      System.out.println(i);
 }

I tested the app in Motorola Xoom - it show "1" when I put one finger but it does nothing when I put two fingers.

I have even added

<uses-feature android:name="android.hardware.touchscreen.multitouch"          android:required="true" />
<uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="true" />
<uses-feature android:name="android.hardware.touchscreen.multitouch.jazzhand" android:required="true" />

in Manifest.xml, but no success.


Solution

  • Currently your onTouchEvent() function is not returning a value. Eclipse won't even build the code without a return value, so I assume that you are returning something in your real application.

    If you are not already doing this, try returning true, so that the system knows that you have handled the current TouchEvent successfully and can move on to the next one.

     public boolean onTouchEvent(MotionEvent event) {
          int i = event.getPointerCount();
          System.out.println(i);
          return true;
     }
    

    Edit:

    Try using an onTouchListener instead of onTouchEvent. Something like this:

    View yourView = findViewById(R.id.id_of_your_view);
    yourView.setOnTouchListener(new View.OnTouchListener()
    {
        @Override
        public boolean onTouch(View v, MotionEvent event)
        {
            int i = event.getPointerCount();
            System.out.println(i);
            return true;
        }
    });