ActionBarSherlock + ViewPager caching is more than just prev / next view

per page: onCreate calls two tabs each time one tab is selected

It explains how ABS (actually ViewPager) works so that ViewPager can scroll. It is clear that you must create at least one of the previous / next pages at the same time.

Is it possible to "cache" more than just the previous / next types (fragments), in a sense:

  • I am on page 1 and I have a network call to get some data (is this done in Activity, not in Fragment - btw. Is this normal?)

  • switch to page 2 and then

  • switch to page 3 and then

  • go to page 1 = Here my page is recreated (using some caching, though, BUT, I don’t need, if possible, rest)

So, it would be nice to cache all pages. How to do it If possible in the current version (4), or will it be some new feature?

Or even the best question, how to delay / disable the destruction of views?

+6
source share
1 answer

I believe this might be useful to someone else, as stated on the website http://storkme.org/2011/12/tabs-done-right-viewpager-and-fragments/

There is already a method that allows you to predetermine the number of "cached" pages that the ViewPager will keep from being recreated.

mViewPager.setOffscreenPageLimit(3); 

Thanks to Jake for reminding me to do another G search :)

+23
source

Source: https://habr.com/ru/post/919200/


All Articles