滑动 TabLayout,重新启动 fragment 在案例 4 到 1 上?

SlidingTabLayout, Restarts fragment On case 4 to 1?

我的 SlidingTabLayout 在从片段标签切换到片段仪表板,或位置 4 到 0 时重新启动我的片段仪表板 activity。 这是我到目前为止编写的代码,任何人都可以说明一下情况吗?

 public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
    public SectionsPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        //2 steps creating a fragment, create the fragment class and create the UI for it
        Fragment fragment = null;
        //we dont want it to return our place holder Fragment instead we want to switch bewtween 3
        //create a switch case based on the position applied or the fragment selected
        switch (position) {
            case HOME:
                fragment = Dashboard.newInstance("","");
                break;
            case TAGS:
                fragment = Tags.newInstance("","");
                break;
            case MY_RECENT:
                fragment = MyPosts.newInstance("","");
                break;
            case TOP:
                fragment = Top.newInstance("", "");
                break;
        }
        return fragment;
    }

    @Override
    public int getCount() {
        // Show 3 total pages.
        return 4;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
            case 0:
                return "Home";
            case 1:
                return "Top";
            case 2:
                return "Recent";
            case 3:
                return "Tags";
        }
        return null;
    }
}

你必须一次加载所有片段,你应该调用这个方法

int size=4;
viewPager.setOffscreenPageLimit(size);

设置adapter后,size是第一次加载的fragment编号