我知道在SO中有一些问题,但是没有人帮助我。
这是我的情况:
标签(当前选中的是粗体)
首页-详细信息-客户-工厂-活动-简而言之
首页-客户-工厂-活动-其他
我只有两个要点:
1:选择了 SOMETHINGELSE 标签页眉,并显示了 ACTIVITIES 内容
2:选择了 ACTIVITIES 标签页眉,并显示了 SOMETHINGELSE 内容
我想要添加的标题是删除并删除显示 ACTIVITIES 选项卡并显示 ACTIVITIES 内容的标题。
private class PagerAdapter extends FragmentStatePagerAdapter {
private int mNumOfTabs;
private SparseArray<MyFragmentsInterface> activeFragments;
private ArrayList<MyHeaderEnum> titles;
MyFragmentsInterface getNewMeterFragmentIfAvailable(int position) {
try {
return activeFragments.get(position);
} catch (Exception ex) {
return null;
}
}
PagerAdapter(FragmentManager fm, int NumOfTabs, ArrayList<MyHeaderEnum> titles) {
super(fm);
this.activeFragments = new SparseArray<>();
this.mNumOfTabs = NumOfTabs;
this.titles = titles;
}
@Override
public int getItemPosition(@NonNull Object object) {
//I played a lot with this part to manage the addiction-removal of tabs before current, but without succeed
return super.getItemPosition(object);
}
void removetitle(int position) {
if (position != -1 && position < titles.size()) {
titles.remove(position);
mNumOfTabs--;
notifyDataSetChanged();
}
}
void addTitle(int position, MyHeaderEnum title) {
titles.add(position, title);
mNumOfTabs++;
notifyDataSetChanged();
}
@Override
public int getCount() {
return mNumOfTabs;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
if (openedIntervention.isInPlace()) {
activeFragments.get(position).save(false);
}
activeFragments.remove(position);
super.destroyItem(container, position, object);
}
@Override
public Fragment getItem(int position) {
MyHeaderEnum currentTitle = titles.get(position);
Bundle bundle = new Bundle();
bundle.putString(_intervention_id_key, interventionID);
currentFragment = newFragment;
//this is to retrieve the correct content for the header
switch (currentTitle) {
case DETTAGLIO:
InterventoDettaglioFragment interventoDettaglioFragment = new InterventoDettaglioFragment();
interventoDettaglioFragment.setArguments(bundle);
newFragment = interventoDettaglioFragment;
return interventoDettaglioFragment;
//... and so on
}
return null;
}
@NonNull
@Override
public Object instantiateItem(ViewGroup container, int position) {
MyFragmentsInterface fragment = (MyFragmentsInterface) super.instantiateItem(container, position);
activeFragments.put(position, fragment);
return fragment;
}
@Override
public CharSequence getPageTitle(int position) {
return titles.get(position).getValue();
}
}
public void manageTabBefore() {
//pre-code to decide if it has to be added or not
if (hasToBeAdded) {
isTabAdded = true;
adapter.addTitle(podTabIndex, MyHeaderEnum.POD);
} else if (hasToBeRemoved) {
isTabAdded = false;
adapter.removetitle(podTabIndex);
}
}
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener()
{
@Override
public void onTabSelected(TabLayout.Tab tab) {
//I also played a looooot with this
int position = tab.getPosition();
viewPager.setCurrentItem(position);
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
我快要放弃了,该怎么做才能在不刷新当前标签和不更改所选标签之前添加一个标签?