我通过替换帧布局来调用视图寻呼机片段,但是当我再次调用它时,视图寻呼机的最后加载片段显示为空白。
//这里我将替换主要活动中的视图寻呼机片段
All_Women_Categories fragment = new All_Women_Categories();
fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.frame_container, fragment).commit();
//这是我所谓的查看分页器片段
public class All_Ethnic_Fragment extends Fragment {
private static SectionsPagerAdapter mSectionsPagerAdapter;
private static ViewPager mViewPager;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View rootView = inflater.inflate(R.layout.all_women_ethnic_view_pager,
container, false);
mViewPager = (ViewPager) rootView.findViewById(R.id.women_ethnic_pager);
mSectionsPagerAdapter = new SectionsPagerAdapter(getActivity()
.getSupportFragmentManager());
mViewPager.setAdapter(mSectionsPagerAdapter);
return rootView;
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return Sarees.newInstance("Hello");
case 1:
return Lehengas.newInstance("Hello");
case 2:
return Salwars_n_Churidars.newInstance("Hello");
case 3:
return Kurtis.newInstance("Hello");
case 4:
return Dress_Materials.newInstance("Hello");
case 5:
return Stitched_Suits.newInstance("Hello");
}
return null;
}
@Override
public int getCount() {
// Show 3 total pages.
return 6;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return getString(R.string.sarees).toUpperCase();
case 1:
return getString(R.string.lehngas).toUpperCase();
case 2:
return getString(R.string.salwars).toUpperCase();
case 3:
return getString(R.string.kurti).toUpperCase();
case 4:
return getString(R.string.dress_material).toUpperCase();
case 5:
return getString(R.string.stiched).toUpperCase();
}
return null;
}
}
}
如果有人得到了什么,那么请告诉我.. 谢谢..
答案 0 :(得分:1)
我不确定我是否收到了您的问题,但我认为您应该堆叠片段而不是替换它们。而不是
.replace(R.id.frame_container, fragment).commit();
您应该尝试使用add(Fragment fragment)
,remove()
和/或show(Fragment fragment)
。这样,您可以先添加所有片段,然后根据需要决定显示/隐藏它们。