Reputation: 772
I have a ViewPager
that use Fragments, i need to swipe with this ViewPager
but in position = x and for some condition i need to jump from this position to next one, so do not display this specific position. what is the method to do this?
Upvotes: 0
Views: 1552
Reputation: 2737
int previousposition=viewPager.getCurrentItem();
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
if (previousPosition > position) {
// here you handle the left scroll
} else {
// and here you handle the right scroll
}
}
@Override
public void onPageSelected(int position) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
Upvotes: 2
Reputation: 2737
viewPager.setCurrentItem(position);
It helps you to move from one position to another.
Upvotes: 1