0
我有一個在我的main.xml佈局文件中定義了4個選項卡的TabHost。我試圖通過向TabHost添加指定的選項卡(即1,2和4,或1和3,或...)來設置選項卡。僅顯示android TabHost中的某些選項卡?
如果我只是添加所有4個選項卡,一切看起來都很好,但如果我將4個選項中的任何一個都取出,那麼我顯示的內容中沒有顯示任何內容。
有沒有人知道這可能是什麼問題?
tabs = (TabHost) findViewById(R.id.tabhost);
tabs.setup();
TabSpec mainSpec = tabs.newTabSpec("Main Tab");
mainSpec.setIndicator("Main", getResources().getDrawable(R.drawable.tab_main)).setContent(R.id.mainContent);
tabs.addTab(mainSpec);
if(param1)
{
TabSpec msgSpec = tabs.newTabSpec("Tab 2");
msgSpec.setIndicator("Messages", getResources().getDrawable(R.drawable.tab_message)).setContent(R.id.messageContent);
tabs.addTab(msgSpec);
}
if(param2)
{
TabSpec tpSpec = tabs.newTabSpec("Tab 3");
tpSpec.setIndicator("Timepoints", getResources().getDrawable(R.drawable.tab_message)).setContent(R.id.timepointContent);
tabs.addTab(tpSpec);
}
if(param3)
{
TabSpec passSpec = tabs.newTabSpec("Tab 4");
passSpec.setIndicator("Passengers", getResources().getDrawable(R.drawable.tab_message)).setContent(R.id.passengerContent);
tabs.addTab(passSpec);
}
理論上我看不出你的代碼有什麼問題。必須有其他的東西導致這一點。 – Squonk 2011-05-19 22:59:10
嗯好吧......我的直覺是它與xml文件中定義的佈局有關,但從未添加到TabHost中? – TomBomb 2011-05-19 23:01:45
啊,好的。我想你可能走上正軌。嘗試在自己的xml文件中爲每個標籤的內容定義佈局。爲TabHost創建一個「主」選項卡布局xml,但將內容視圖保持爲獨立的佈局。 – Squonk 2011-05-19 23:05:34