even when I set oViewPager.setOffscreenPageLimit(0) my view pager still loads 1 off screen page on each side of the visible page.
How do I make it only load the page when the user slides to it?
My adapter if it helps:
public class MainPagerAdapter extends FragmentPagerAdapter {
protected static final String[] CONTENT = new String[] { "page 1", "page 2", "page 3", "page 4", };
private int mCount = CONTENT.length;
public MainPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
//return TestFragment.newInstance(CONTENT[position % CONTENT.length]);
return MainFragment.newInstance(position);
}
@Override
public int getCount() {
return mCount;
}
@Override
public CharSequence getPageTitle(int position) {
return MainPagerAdapter.CONTENT[position % CONTENT.length];
}
public void setCount(int count) {
if (count > 0 && count <= 10) {
mCount = count;
notifyDataSetChanged();
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…