Last active
August 29, 2015 14:23
-
-
Save seventhmoon/5e6831a64a0fe3f97109 to your computer and use it in GitHub Desktop.
LoopingViewPager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Insert 2 more element to the first and the last of the list of the ViewPager | |
// e.g. from {A, B, C} to {C, A, B, C, A}, connecting the first to the last |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//implement ViewPager.SimpleOnPageChangeListener(), override the following method | |
public void onPageScrollStateChanged(int state) { | |
if (state == ViewPager2.SCROLL_STATE_IDLE) { | |
int curr = mViewPager.getCurrentItem(); | |
int lastReal = mViewPager.getAdapter().getCount() - 2; | |
if (curr == 0) { | |
mViewPager.setCurrentItem(lastReal, false); | |
} else if (curr > lastReal) { | |
mViewPager.setCurrentItem(1, false); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment