Search code examples
androidpagertabstrip

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;
    }

}

Solution

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