I have used ViewPager
with Fragment
.
But it loads two pages at time.
Is there any way to load only one page in viewpager ?
Asked
Active
Viewed 1.9k times
13

Bhavin Nattar
- 3,189
- 2
- 22
- 30

kirankk
- 628
- 1
- 9
- 22
-
Have a look on this: https://stackoverflow.com/a/44405015/7874047 – Ronak Thakkar Jun 07 '17 at 06:31
3 Answers
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
-
2I 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