我有一個tabhost和我添加有3活動(每片一個活性)。 我需要知道如何在每次更改標籤時在活動中調用新實習生。 我爲tabhost添加了一個監聽器。當我使用clearAllTabs();
方法並將所有選項卡再次添加到偵聽器中時,應用程序崩潰。 當我使用代碼toto從視圖中刪除用戶單擊的特定選項卡tabHost.getTabWidget().removeView(tabHost.getTabWidget().getChildTabViewAt(i)); tabHost.addTab(the tab I want to replace);
刷新活動內部tabhost
然後新選項卡位於tabhost的末尾。
我只需要的是如何給每個用戶clickes特定的標籤頁時重新加載相稱活動的例子。
我的代碼:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ActionBar bar = getSupportActionBar();
// requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
Resources res = getResources();
LocalActivityManager mlam = new LocalActivityManager(this, false);
final TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
mlam.dispatchCreate(savedInstanceState);
tabHost.setup(mlam);
TabHost.TabSpec spec;
Intent intent;
// TabHost tabHost = getTabHost();
// tabHost.setup();
TabSpec specAll = tabHost.newTabSpec("All");
specAll.setIndicator("All");
Intent allIntent = new Intent(this, allActivity.class);
specAll.setContent(allIntent);
// specAll.setContent(R.id.allList);
Log.d("SpecAll",""+specAll.setContent(allIntent));
TabSpec specIn = tabHost.newTabSpec("in");
specIn.setIndicator("In");
Intent inIntent = new Intent(this, inActivity.class);
specIn.setContent(inIntent);
TabSpec specOut = tabHost.newTabSpec("Out");
specOut.setIndicator("Out");
Intent outIntent = new Intent(this, outActivity.class);
specOut.setContent(outIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(specAll); // Adding all tab
tabHost.addTab(specIn); // Adding in tab
tabHost.addTab(specOut); // Adding out tab
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
int i = tabHost.getCurrentTab();
//Log.i("@@@@@@@@ ANN CLICK TAB NUMBER", "------" + i);
if (i == 0) {
Log.d("TAB","" +i);
} else if (i == 1) {
Log.d("TAB","" +i);
}
else
Log.d("TAB", ""+i);
}
});
}
我也遇到這個問題,雖然略有不同:我想在一個標籤中替換活動。我沒有找到解決方案,但保存所有標籤內容,關閉TabActivity,立即重新打開並恢復內容。我相信有更好的解決方案。 – FWeigl 2012-08-14 09:12:05
我發佈瞭解決方案隊友。歡呼聲 – mkounal 2012-08-14 15:23:04