从片段选项卡寻呼机示例中删除选项卡
我正在尝试使用 Fragment Tabs Pager 示例: API 4+ 支持演示/片段选项卡分页器 并添加删除选项卡的功能,因为我需要能够添加和删除选项卡。
我已经尝试过:
public void removeTab(int position) {
mTabHost.getTabWidget().removeView(mTabHost.getTabWidget().getChildTabViewAt(position));
}
但这不起作用。
我还尝试删除所有选项卡并使用最初添加选项卡时存储的 tabSpec 重新添加它们:
public void removeTab(int position) {
mTabHost.setCurrentTab(0);
mTabHost.clearAllTabs();
ArrayList<TabInfo> mNewTabs = new ArrayList<TabInfo>();
mTabs.remove(position);
int len = mTabs.size();
for (int i = 0; i < len; i++) {
TabInfo info = new TabInfo(mTabs.get(i).tag, mTabs.get(i).clss, mTabs.get(i).args, mTabs.get(i).tabSpec);
mNewTabs.add(info);
}
mTabs.clear();
mViewPager.removeAllViews();
mTabHost.getTabWidget().getChildAt(position).setVisibility(View.GONE);
for (int i = 0; i < len; i++) {
addTab(mNewTabs.get(i).tabSpec, mNewTabs.get(i).clss, mNewTabs.get(i).args);
}
notifyDataSetChanged();
}
这将删除选项卡,但当选项卡已实例化时,然后在添加新选项卡时显示原始片段。
任何人都可以帮助我解决这个能够删除和添加选项卡或替换选项卡中的片段的问题。
I'm trying to use the Fragment Tabs Pager example:
API 4+ Support Demos/Fragment Tabs Pager and add the abillity to delete a tab, because I need to be able to add and remove tabs.
I've tried:
public void removeTab(int position) {
mTabHost.getTabWidget().removeView(mTabHost.getTabWidget().getChildTabViewAt(position));
}
but this does not work.
I've also tried removing all the tabs and re-adding them with the tabSpec which I stored when initially adding the tabs:
public void removeTab(int position) {
mTabHost.setCurrentTab(0);
mTabHost.clearAllTabs();
ArrayList<TabInfo> mNewTabs = new ArrayList<TabInfo>();
mTabs.remove(position);
int len = mTabs.size();
for (int i = 0; i < len; i++) {
TabInfo info = new TabInfo(mTabs.get(i).tag, mTabs.get(i).clss, mTabs.get(i).args, mTabs.get(i).tabSpec);
mNewTabs.add(info);
}
mTabs.clear();
mViewPager.removeAllViews();
mTabHost.getTabWidget().getChildAt(position).setVisibility(View.GONE);
for (int i = 0; i < len; i++) {
addTab(mNewTabs.get(i).tabSpec, mNewTabs.get(i).clss, mNewTabs.get(i).args);
}
notifyDataSetChanged();
}
This removes the tab, but when the tab had been instantiated, then when adding a new tab the original fragment is displayed.
Can anyone help me to solve this problem of being able to remove and add tabs or replace the fragment within a tab.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论