This worked for me.
ViewPager.OnPageChangeListener onPageChangeListener = new ViewPager.OnPageChangeListener() {
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
// disable swipe
if(!swipeEnabled) {
if (viewPager.getAdapter().getCount()>1) {
viewPager.setCurrentItem(1);
viewPager.setCurrentItem(0);
}
}
}
public void onPageScrollStateChanged(int state) {}
public void onPageSelected(int position) {}
};
viewPager.addOnPageChangeListener(onPageChangeListener);