2
問題是:我有一個TabHost
帶有4個選項卡(請參閱下面的代碼),我在MainMenuActivity
類中獲得了Button
。 Button
設置爲OnClickListener
,如果它被點擊,我希望它進入第二個選項卡。我嘗試過setCurrentTab(1)
,但這只是搞砸了項目。我能做什麼?在特定標籤中啓動Android應用程序
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setTabs() ;
}
private void setTabs()
{
addTab("Home", R.drawable.tab_home, MainMenuActivity.class);
addTab("Calculate", R.drawable.tab_search, SpinnerClass.class);
addTab("Search", R.drawable.tab_home, ScrollView1.class);
addTab("Premium", R.drawable.tab_search, ScrollView2.class);
}
private void addTab(String labelId, int drawableId, Class<?> c)
{
TabHost tabHost = getTabHost();
Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);
View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
TextView title = (TextView) tabIndicator.findViewById(R.id.title);
title.setText(labelId);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
嘿,我有一個問題。我有水平滾動視圖,其中我有我的tabhost.tabHost.setCurrentTab(索引)設置當前標籤,但滾動視圖必須設置爲滾動到當前標籤不工作。請你幫我? – Nevaeh 2015-04-20 09:09:34