I want to load only one page at a time.
viewpager.setOffscreenPageLimit(0);
is not working.
I want to load only one page at a time.
viewpager.setOffscreenPageLimit(0);
is not working.
you can't do that with a standard ViewPager implementation. If you see sources, you will see, that it sets offscreen page limit to 1, if it is less than 1.
public void setOffscreenPageLimit(int limit) {
if (limit < DEFAULT_OFFSCREEN_PAGES) { //DEFAULT_OFFSCREEN_PAGES if 1
Log.w(TAG, "Requested offscreen page limit " + limit + " too small; defaulting to " +
DEFAULT_OFFSCREEN_PAGES);
limit = DEFAULT_OFFSCREEN_PAGES;
}
if (limit != mOffscreenPageLimit) {
mOffscreenPageLimit = limit;
populate();
}
}
You can try to override this method in your custom class.
Why would you want to set the offline page limit to zero?
Having it set to one allows android to pre-emptively load the next view to the view pager improving the user experience and speeding up the load time.
If you must set it to zero then create a custom view pager class that extends ViewPager and then override the setOffScreenPageLimit method