onClick on ViewPager not triggered

I solved a similar problem by using a GestureDetector

Sending the MotionEvent to the GestureDetector

tapGestureDetector = new GestureDetector(this, new TapGestureListener());

viewPager.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            tapGestureDetector.onTouchEvent(event);
            return false;
        }
});

It you are using the compatibility library, you can change the first line to:

tapGestureDetector = new GestureDetectorCompat(this, new TapGestureListener());

You can handle your Event in the GestureListener:

        class TapGestureListener extends GestureDetector.SimpleOnGestureListener{

         @Override
         public boolean onSingleTapConfirmed(MotionEvent e) {
           // Your Code here
         }
        }

Leave a Comment

tech