ViewPagerIndicator选项卡丢失内容

时间:2013-05-22 08:46:31

标签: android android-fragments viewpagerindicator android-holo-everywhere

我正在使用HoloeverywhereViewPagerIndicator;使用Holoeverywhere1我使用sliderFragment中实施了ViewPagerIndicator和标签。一切都很好,滑块工作,菜单,标签;标签只在第一次正常工作时,当我使用Fragment移动到其他slider并返回标签Fragment时,内容不再可用。

创建标签的Fragment代码

public class SeconFrag extends Fragment {

    ViewPager mViewPager;
    FragmentAdapter mTabsAdapter;
    PageIndicator mIndicator;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        mTabsAdapter = new FragmentAdapter(getSupportFragmentManager());


        View view = inflater.inflate(R.layout.second_frag);
        mViewPager = (ViewPager) view.findViewById(R.id.pager);
        mViewPager.setAdapter(mTabsAdapter);



        TitlePageIndicator indicator = (TitlePageIndicator) view
                .findViewById(R.id.indicator);
        indicator.setViewPager(mViewPager);
        indicator.setFooterIndicatorStyle(IndicatorStyle.Triangle);
        mIndicator = indicator;

        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        getSupportActionBar().setSubtitle("Create");

    }


}

FragmentAdapter代码

public class FragmentAdapter extends FragmentPagerAdapter{
    protected static final String[] CONTENT = new String[] { "Choose", "Customise" };

    private int mCount = CONTENT.length;

    public FragmentAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        if (position == 0) {
            return  TabOne.newInstance();
        } else if (position == 1) {
            return  TabTwo.newInstance();
        }else if (position == 3 ) {
            return  TabOne.newInstance();
        }else 
            return  null;

    }

    @Override
    public int getCount() {
        return mCount;
    }

    @Override
    public CharSequence getPageTitle(int position) {
      return FragmentAdapter.CONTENT[position % CONTENT.length];
    }

    public void setCount(int count) {
        if (count > 0 && count <= 10) {
            mCount = count;
            notifyDataSetChanged();
        }
    }
}
选项卡Fragment

上的

public final class TabOne extends Fragment {

    public static TabOne newInstance() {
        TabOne fragment = new TabOne();
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View myFragmentView = inflater.inflate(R.layout.tab_one, container,
                false);
        return myFragmentView;
    }
}

SeconFrag OnPause()我删除了Fragment没有运气,hide()OnPause()中删除,并尝试show()在{ {1}}更改OnResume()后仍未显示内容。

修改

First time opening the fragment Change Fragment using slider Contents gone

0 个答案:

没有答案