androidmulti-touchandroid-gesture

MotionEvent.getPointerCount() is always 1


I'm somehow getting unexpected results while trying to implement multitouch in my app. I'm never getting data for more than one pointer. Multitouch on my phone surely works, because I can pinch-zoom in browser and detect pinch gesture with GestureDetector, but the following sample prints action=0 pointers=1 regardless of how many fingers I use to touch the screen.

Is there something in configuration/AndroidManifest or Activity creation that I need to

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    findViewById(R.id.ll1).setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Log.d("TAG","onTouch action="+event.getAction()+" pointers="+event.getPointerCount());
            return false;
        }
    });
}

layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ll1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
</LinearLayout>

Solution

  • The problem was that I was returning false in onTouch, therefore new touch events have not been generated.