0
我有類CustomTab延伸TabActivity:Switch選項卡機器人但內容不會改變
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_tab);
tabHost = getTabHost();
Intent intentA = new Intent(getBaseContext(), A.class);
Intent intentB = new Intent(getBaseContext(), B.class);
Intent intentC = new Intent(getBaseContext(), C.class);
TabSpec tabA = tabHost
.newTabSpec("a")
.setIndicator("",
getResources().getDrawable(R.drawable.icon_a))
.setContent(intentA);
TabSpec tabB = tabHost
.newTabSpec("b")
.setIndicator(
"",
getResources()
.getDrawable(R.drawable.icon_b))
.setContent(intentB);
TabSpec tabC = tabHost
.newTabSpec("c")
.setIndicator("",
getResources().getDrawable(R.drawable.icon_c))
.setContent(intentC);
tabHost.addTab(tabA);
tabHost.addTab(tabB);
tabHost.addTab(tabC);
tabHost.setCurrentTab(0);
和活性B:
Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.b);
((CustomTab) getParent()).getTabHost().setCurrentTab(3);
我想運行活動B時的切換到接頭3(活性C)所以我試着用「((CustomTab)getParent())。getTabHost()。setCurrentTab(3);」它只改變標籤,但內容不變,我創建了一個類似的話題,但沒有收到正確答案。
「它只改變標籤,但內容不會改變」因爲您已經編寫了用於更改Tab的代碼,所以它只會更改Tab。您還有代碼在您的活動B中加載活動在您的選項卡3中。 – GrIsHu 2013-03-28 04:18:03
嘗試此操作.........((CustomTab)getParent())。getTabHost()。setCurrentTab(2); – Madhuri 2013-03-28 04:31:35
我想只是setCurrentTab,因爲它的內容已經寫在CustomTab類中:TabSpec .... setContent(...)。我將嘗試 – rocky 2013-03-28 04:32:01