13

I have used ViewPager with Fragment.
But it loads two pages at time.
Is there any way to load only one page in viewpager ?

Bhavin Nattar
  • 3,189
  • 2
  • 22
  • 30
kirankk
  • 628
  • 1
  • 9
  • 22

3 Answers3

4

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.

Community
  • 1
  • 1
SKK
  • 5,261
  • 3
  • 27
  • 39
3

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.

Pawan Maheshwari
  • 15,088
  • 1
  • 48
  • 50
0

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;
user1047504
  • 578
  • 7
  • 14
  • 2
    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 – Prakash Jul 28 '16 at 19:58