I have used ViewPager
with Fragment
.
But it loads two pages at time.
Is there any way to load only one page in viewpager ?
SKK
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;
来源:https://stackoverflow.com/questions/17611707/load-only-one-fragment-in-viewpager