Aitor Ramos Pajares
Aitor Ramos Pajares

Reputation: 361

ViewPager only load the fragments once time

I have an android DrawerLayout and it has 2 items, one of them is a fragment with a PagerTabStrip and it load their fragments but when I change the item of the DrawerLayout and I come back to the PagerTabStrip it loads the tabs, but doesn't their fragments.

This is my PagerTabStrip class

public class maintabs extends Fragment {

    FragmentPagerAdapter adapterViewPager;
    PagerTabStrip pagerTabStrip;
    View rootView;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.tabs_main, container, false);
        ViewPager vpPager = (ViewPager) rootView.findViewById(R.id.vpPager);
        pagerTabStrip = (PagerTabStrip) rootView.findViewById(R.id.pager_header);
        pagerTabStrip.setDrawFullUnderline(true);
        adapterViewPager = new SampleFragmentPagerAdapter(getFragmentManager());

        vpPager.setAdapter(adapterViewPager);
        return  rootView;
    }

}

Upvotes: 1

Views: 1113

Answers (1)

Aitor Ramos Pajares
Aitor Ramos Pajares

Reputation: 361

I've found a solution. Just use a FragmentStatePagerAdapter instead FragmentPagerAdapter

Upvotes: 3

Related Questions