I set a click listener on a ViewPager
, but the onClick event is never called. I guess the touch event detection of the ViewPager
is interfering, but I can't see how to solve it...
Anybody could help?
Thanks
mViewPager.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // never called } });
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 } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With