0
我已經搜索了這個解決方案,但可以找到任何有用的東西,任何人都可以告訴我,我可以從TabHost中刪除特定的標籤/ TabSpec。我爲每個tabSpec製作對象並將其保存在arrayList中。下面的代碼:在Android中動態刪除標籤
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.getCurrentTab()..你可以在logcat或toastmessage中使用它來知道。如果它有幫助,請評價它 –