我已经搜索了这个解决方案,但可以找到任何有用的东西,任何人都可以告诉我我可以从 TabHost 中删除特定的选项卡/TabSpec。我正在为每个 tabSpec 创建对象并将其保存在 arrayList 中。代码如下:
public class Main extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
final TabHost tabs=(TabHost)findViewById(R.id.tabhost);
tabs.setup();
final ArrayList<TabHost.TabSpec> list = new ArrayList<TabHost.TabSpec>();
TabHost.TabSpec spec= tabs.newTabSpec("buttontab");
spec.setContent(R.id.buttontab);
spec.setIndicator("Button");
tabs.addTab(spec);
list.add(spec);
tabs.setCurrentTab(0);
Button btn=(Button)tabs.getCurrentView().findViewById(R.id.buttontab);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
TabHost.TabSpec spec=tabs.newTabSpec("tag1");
spec.setContent(new TabHost.TabContentFactory() {
public View createTabContent(String tag) {
return(new AnalogClock(Main.this));
}
});
spec.setIndicator("Clock");
tabs.addTab(spec);
list.add(spec);
}
});
}
}
最佳答案
您可以使用此代码来实现该目的
tabHost.getTabWidget().removeView(tabHost.getTabWidget().getChildTabViewAt(3));
要获取选项卡编号,请使用tabHost.getCurrentTab()
关于java - Android 中动态删除选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21368518/