【发布时间】:2015-04-21 09:29:36
【问题描述】:
我需要在特定条件下隐藏第二个选项卡,我尝试了以下方式,选项卡隐藏,文本也改变了,但片段没有改变,我的意思是,如果我隐藏了第二个选项卡,那么我得到 @ 987654321@[第二个标签的内容] 在第三个标签上,
public class PagerAdapter extends FragmentPagerAdapter {
private static final String TAG = "PagerAdapter";
private final String[] TITLES_WITH_STEP2 = {"step1", "step2", "step3", "step4"};
private final String[] TITLES_WITHOUT_STEP2 = {"step1", "step3", "step4"};
private ArrayList<Fragment> fragmentsList;
private boolean isShowStep2Tab = true;
public PagerAdapter(FragmentManager fm) {
super(fm);
fragmentsList = new ArrayList<>();
fragmentsList.add(new FragmentStep1());
fragmentsList.add(new FragmentStep2());
fragmentsList.add(new FragmentStep3());
fragmentsList.add(new FragmentStep4());
}
@Override
public CharSequence getPageTitle(int position) {
Log.v(TAG, "getPageTitle isShowStep2Tab : " + isShowStep2Tab);
fragmentsList = new ArrayList<>();
return isShowStep2Tab ? TITLES_WITH_STEP2[position] : TITLES_WITHOUT_STEP2[position];
}
@Override
public Fragment getItem(int position) {
/*Log.v(TAG, "getItem isShowStep2Tab : " + isShowStep2Tab);
if (getPageTitle(position).equals("Step1")) {
return new FragmentStep1();
} else if (getPageTitle(position).equals("Step2")) {
return new FragmentStep2();
} else if (getPageTitle(position).equals("Step3")) {
return new FragmentStep3();
} else if (getPageTitle(position).equals("Step4")) {
return new FragmentStep4();
}else {
return new FragmentStep4();
}*/
return fragmentsList.get(position);
}
@Override
public int getCount() {
Log.v(TAG, "getCount isShowStep2Tab : " + isShowStep2Tab);
fragmentsList = new ArrayList<>();
return isShowStep2Tab ? TITLES_WITH_STEP2.length : TITLES_WITHOUT_STEP2.length;
}
public void setShowFamilyTab(boolean isShowStep2Tab) {
this.isShowStep2Tab = isShowStep2Tab;
fragmentsList = new ArrayList<>();
if (isShowStep2Tab) {
fragmentsList.add(new FragmentStep1());
fragmentsList.add(new FragmentStep2());
fragmentsList.add(new FragmentStep3());
fragmentsList.add(new FragmentStep4());
} else {
fragmentsList.add(new FragmentStep1());
fragmentsList.add(new FragmentStep3());
fragmentsList.add(new FragmentStep4());
}
notifyDataSetChanged();
}
}
我不知道这里有什么问题。
【问题讨论】:
-
投反对票的原因...
标签: android pagerslidingtabstrip