Ahmet K
Ahmet K

Reputation: 813

Sliding Tab is reloading Fragment after changing Tab

Im using these classes for my Tabs:

https://github.com/google/iosched/blob/master/android/src/main/java/com/google/samples/apps/iosched/ui/widget/SlidingTabLayout.java

https://github.com/google/iosched/blob/master/android/src/main/java/com/google/samples/apps/iosched/ui/widget/SlidingTabStrip.java

I have 3 Tabs : Tab1 Tab2 and Tab3.

In Tab3 Im loading contacts from my phone and add them into my ListView.This takes a while till it loaded successfuly (200 contacts).

Now my problem is : When I change my Tab from Tab3 to Tab1 the loading process begins again.So the Fragment is loading from zero again.

So everytime I change to Tab 1 and go back to Tab 3 everything has to be loaded again. Someone got an Idea to find a solution for it ? How can I prevent this Fragment reload ?

@Override
 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.tab_friends, container, false);

    LV_Contacts = (ListView)v.findViewById(R.id.LV_Contacts);
    if(adapter_contacts == null)
        new load_contacts().execute();



    return v;
}

EDIT: When I change from Tab3 to Tab2 its working fine.It just continues but when I go to Tab1 everything starts from the beginning and it builds the Listview again

Upvotes: 0

Views: 924

Answers (1)

awaistoor
awaistoor

Reputation: 786

all you need is to add this

viewPager.setOffscreenPageLimit(3);

for more detail read doc

http://developer.android.com/reference/android/support/v4/view/ViewPager.html#setOffscreenPageLimit(int)

Upvotes: 4

Related Questions