I have a ViewPager, and FragmentPagerAdpater and 3 Fragments to implement an tab swipe view. Is the ViewPager supposed to "remember" the 3 views after first time rendering?
My problem is that after some time, the layouts of the 3 views are "forgotten". That means I need to update them again and user will see the ugly part before updating.
Is there a view holder pattern for viewpager as well? What technique can i use to remain those already rendered views or preventing them being destroyed?
You can use ViewPager
setOffscreenPageLimit()
to control how many pages are kept in memory and pre-created before being scrolled to. By default its value is 1, meaning it will keep the current page in memory and the pages just before and after it. Depending on your page size (full-screen or partial screen), increasing it to e.g. 2 will prevent the page being constructed on-screen.
In your tabs adapter just override the destroyItem() method & quote out the super statement
this will save the instance of your fragments and they wont need to load again and again
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
// TODO Auto-generated method stub
// super.destroyItem(container, position, object);
}
something like this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With