Android | Stop Tablayout Reload/refresh My Fragments
Solution 1:
As you can see in the Documentation setOffscreenPageLimit
Inside your function setupViewPager(ViewPager viewPager) add this:
viewPager.setOffscreenPageLimit(limitNumberOfPages); //before setAdapter
viewPager.setAdapter(adapter);
And the limitNumberOfPages is an int that contains the amount of pages that can be scrolled without reloading the fragments. If you have 4 tabs, you should use:
int limitNumberOfPages = 3;
The default number for this property is 1.
Solution 2:
I solved it by myself Simple, use:
viewPager.setOffscreenPageLimit(numberOfPages);
From reference: Set the number of pages that should be retained to either side of the current page in the view hierarchy in an idle state.
In my case, I need 3 pages that should be retained.
Solution 3:
ViewPager holds Fragments left and/or right of the selected Tab. This is needed for fast animating tab change.
You can keep references of your Fragments in Your Activity, but this references can be null.
Post a Comment for "Android | Stop Tablayout Reload/refresh My Fragments"