我正在使用Holoeverywhere
和ViewPagerIndicator
;usingHoloeverywhere1
我在 using 中实现了和slider
选项卡。一切正常,滑块工作,其中的菜单,选项卡;选项卡只有第一次才能正常工作,当我使用移动到其他选项卡并返回选项卡时,内容不再可用。Fragment
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()
在更改OnResume()
后仍然没有显示内容Fragment
。
编辑