May be duplicate of:
- Intercepting touch events in ViewPagerIndicator
- Disabling & Enabling Paging In ViewPager in Android
- android: ViewPager and HorizontalScrollVIew
I am using ViewPagerIndicator in my android app for swiping dynamic number of view and its working fine.
What is want? When user click on one of the slide its corresponding view will open. But i am unable to override touch event on Pager.
Activity code is :
public class MainActivity extends BaseSampleActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAdapter = new TestFragmentAdapter(getSupportFragmentManager());
mPager = (ViewPager)findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
mPager.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
System.out.print(event.getAction());//not working
return false;
}
});
mIndicator = (CirclePageIndicator)findViewById(R.id.indicator);
mIndicator.setViewPager(mPager);
}
}
I have searched a lot but didn't found proper solution. But haven't got proper and brief answer
I also had a same issue. First I created a
CustomViewPager
, which extendsViewPager
:and override
onTouch
andonInterceptTouch
events:Your xml should be:
Change it to
For click event use
GestureDetector
. SendingMotionEvent
to the tapGestureDetector.If you are using the compatibility library, you can change the first line to:
You can handle your Event in the GestureListener: