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?
Asked
Active
Viewed 1,508 times
0
-
1Here is a great answer: [enter link description here](http://stackoverflow.com/questions/18413309/how-to-implement-a-viewpager-with-different-fragments-layouts) – BigPun86 Oct 21 '15 at 12:06
2 Answers
2
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) {
}
});

naXa stands with Ukraine
- 35,493
- 19
- 190
- 259

Rohit Heera
- 2,709
- 2
- 21
- 31
1
viewPager.setCurrentItem(position);
It helps you to move from one position to another.

naXa stands with Ukraine
- 35,493
- 19
- 190
- 259

Rohit Heera
- 2,709
- 2
- 21
- 31
-
how i can specify the position?? i mean if the user scroll right i make position=position +2; and left position=position-2 ; but how i can get if he swipe left or right – Amalo Oct 21 '15 at 12:20
-
I post another solution according to your requirement plz check it . – Rohit Heera Oct 21 '15 at 12:27