Load only one Fragment in ViewPager

拜拜、爱过 提交于 2019-12-04 00:28:57
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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!