I have used ViewPager
with Fragment
.
But it loads two pages at time.
Is there any way to load only one page in viewpager ?
Load only one Fragment in ViewPager
Have a look on this: https://mcmap.net/q/56174/-how-can-make-my-viewpager-load-only-one-page-at-a-time-ie-setoffscreenpagelimit-0 –
Via
This might be the thing you are looking for:
mPager.setOffscreenPageLimit(n); // where n is the number of offscreen pages you want to load.
**The minimum value of it can be "1" as you said. ** check this link and also read the comments.
setOffScreenPageLimit method has a limit of minimum 1. If you'll try to set smaller limit than this, it will use its default value which is 1.
You can try to do manual your adapter such as
public int currentIndex;
@Override
public Fragment getItem(int index) {
if(position == currentIndex){
return new EmptyFragment();
}else{
return new YourNormalFragment();
}
}
and becareful to modify
yourViewPager.setCurrentItem(index);
along with
yourAdapter.currentIndex = index;
I don't think this this would work. getItem will be called twice with index and index+1 depending on how you swipe your views –
Arboreal
© 2022 - 2024 — McMap. All rights reserved.