我在我的应用程序中使用片段作为标签,每当我尝试更改标签时,这就是我得到的错误。当我更改标签一次时它工作正常,但当我尝试再次更改标签时它会给我错误。我在我的代码中放了removeView,但它没有用。这是错误发生的地方
private void initialiseTabHost(Bundle args) {
mTabHost = (TabHost)findViewById(android.R.id.tabhost);
mTabHost.setup();
TabInfo tabInfo = null;
TabbedActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab1").setIndicator("Tab 1"), (tabInfo = new TabInfo("Tab1", MainFeed.class, args)));
this.mapTabInfo.put(tabInfo.tag, tabInfo);
TabbedActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab2").setIndicator("Tab 2"), (tabInfo = new TabInfo("Tab2", MapViewActivity.class, args)));
this.mapTabInfo.put(tabInfo.tag, tabInfo);
TabbedActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab3").setIndicator("Tab 3"), (tabInfo = new TabInfo("Tab3", Tab3Fragment.class, args)));
this.mapTabInfo.put(tabInfo.tag, tabInfo);
TabbedActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab4").setIndicator("Tab 4"), (tabInfo = new TabInfo("Tab4", Tab4Fragment.class, args)));
this.mapTabInfo.put(tabInfo.tag, tabInfo);
// Default to first tab
this.onTabChanged("Tab1");
//
mTabHost.setOnTabChangedListener(this);
}
以下是我调用此方法切换标签的方法。
ViewGroup parent = (ViewGroup) view.getParent();
parent.removeView(view);
MainFeed.getTabbedActivity().onTabChanged(getString(R.string.tab1));
如果我要移除视图,为什么它仍然会给我这个例外,我该如何修复?