Question

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...

Était-ce utile?

La solution

Try to use setOffscreenPageLimit method:

mViewPager.setOffscreenPageLimit(3);

It works for me.

Autres conseils

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
        }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top