2011-04-10 33 views
0

的活性及第二的一個選項卡我想有一個TabHost它由兩個選項卡:一個從ViewR.id.something)創建並從Activity第二個。TabHost:視圖

所以我是這樣做的:

mTab = (TabHost) findViewById(R.id.tabhost); 
     mTab.setup(); 
     TabHost.TabSpec spec = mTab.newTabSpec("All"); 

spec.setContent(R.id.all_tab); // Created from View 
     spec.setIndicator("All", getResources().getDrawable(R.drawable.emo_im_cool)); 
     mTab.addTab(spec); 

Intent intent = new Intent().setClass(this, TasksDone.class); 
     spec = mTab.newTabSpec("Done"); 
     spec.setIndicator("Done", getResources().getDrawable(R.drawable.emo_im_happy)); 
     spec.setContent(intent); // Created from Intent 
     mTab.addTab(spec); 

之後,第一個選項卡上的內容是不可見的,但它的存在,因爲我看到我的點擊反應。

出現如果我設置第二個選項卡的setContentView,而不是intent

你們知道爲什麼第一頁上的內容是不可見的嗎?

+0

你的意思是標籤「全部」不顯示? – 2011-04-10 17:07:08

+0

標籤顯示「全部」,但它的內容不是。 – Eugene 2011-04-10 17:26:13

回答

0

恩,你試過spec.setContent(R.layout.all)?我認爲應該有一個佈局ID,而不是一個視圖對象的ID。

+0

不是,應該是視圖對象。 – Eugene 2011-04-10 17:33:48

+0

好的,是的,我在編輯中看到你可以捕捉點擊事件... – 2011-04-10 17:34:42

0

問題的根源是xml中的一個錯誤。

相關問題