Try to use setOffscreenPageLimit
method:
mViewPager.setOffscreenPageLimit(3);
It works for me.
题
I use ActionBar with 3 swipe-tabs.
First-Tab : get a ListView from data of my server when onCreate() & onResume().
Second-Tab : get a ListView from data of my server when onCreate()
Third-Tab : get a some data of my server when onCreate()
Here is a question, When I swipe to Third-Tab and re-back to First-Tab, First-Tab's Fragment is going to onCreate() -> so re-downloading data from my server, and It looks uneffective...
How can I keep my fragment? Please help...
解决方案
其他提示
Write this code in all the three fragments you have. This will allow your fragment to inflate the view when its not already inflated.
if (view != null) {
ViewGroup parent = (ViewGroup) view.getParent();
parent.removeView(view);
} else {
//inflate your view here
}