I'm migrating my ViewPager to the new ViewPager2. Unfortunately with this new class, the setOnTouchListener
is never called.
mViewPager.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
LogUtils.LOGD("XXXX", "motionEvent.getAction()=" + motionEvent.getAction());
...
return false;
}
});
Do you know how can I fix it?
Thank you very much guys!
Because ViewPager2 is a ViewGroup, the final target is the recyclerview in it. The setOnTouchListener
not called is because recyclerview intercepts the event and calls the onTouchEvent
first.
The right way to add customised onTouch logic is to call
mViewPager.getChildAt(0).setOnTouchListener{...}
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