我使用viewpager
和TabFragment
构建了手动滑动标签的项目。我还有几周的错误,当我从viewpager
和tab
删除项目时,它的成功但是当我创建新项目时,之前删除的项目再次显示在同一位置。我能做什么?请给我最好的问候,我的项目会迟到。这是我的代码。
删除按钮代码:
btCloseTab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(COUNT_TAB>0) {// Check first count tab is 1 and more
if(TAB_CURRENT>=0 && PAGE_CURRENT>=0) { //Check Tab currunt and page curunt value is grater then equal to 0
try {
viewPager.removeViewAt(PAGE_CURRENT);
actionBar.removeTabAt(TAB_CURRENT);
COUNT_TAB -= 1;
mAdapter.notifyDataSetChanged();
viewPager.destroyDrawingCache();
my_tabList_array.remove(PAGE_CURRENT);
iTabListAdapter.notifyDataSetChanged();
TAB_TAG-=1;
}catch(Exception e){
e.printStackTrace();
}
}
}
}
});
我的适配器类
public class TabsPageAdapter extends FragmentStatePagerAdapter {
public TabsPageAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int i) {
/*Fragment fragment = new SwipClass();
Bundle args = new Bundle();
args.putInt(SwipClass.ARG_TAB_POSITION, i);
fragment.setArguments(args);
return fragment;*/
return new SwipClass();
}
@Override
public int getItemPosition(Object object) {
return PagerAdapter.POSITION_NONE;
}
@Override
public int getCount() {
return COUNT_TAB;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
super.destroyItem(container, position, object);
FragmentManager manager = ((Fragment)object).getFragmentManager();
android.support.v4.app.FragmentTransaction trans = manager.beginTransaction();
trans.remove((Fragment)object);
trans.commit();
}
}
当我添加标签时,我使用了这段代码
actionBar.addTab(actionBar.newTab().setText("New Tabs").setTag(""+TAB_TAG)
.setTabListener(HomeActivity.this));
请您最好的问候和答复,提前致谢