2011-02-11 20 views
1

我正在製作一個應用程序,其中m使用Tab Bars。 現在我需要知道的是,如何通過setOnTabChangedListener()在我的代碼如何通過TabBars調用活動

例如打開其他製表符。我目前在標籤中,當我點擊第二個標籤時,它應該調用第二個標籤的活動。

回答

3

看到下面的代碼

TabHost tabHost = getTabHost(); // The activity TabHost 
     TabHost.TabSpec spec; // Reusable TabSpec for each tab 
     Intent intent; // Reusable Intent for each tab 

     // Create an Intent to launch an Activity for the Movies tab. 
     intent = new Intent().setClass(this, BarActivity.class); 
     // Initialise a TabSpec for the Movies tab and add it to the TabHost. 
     spec = tabHost.newTabSpec("Nights").setIndicator("Nights").setContent(intent); 
     tabHost.addTab(spec); 

     // Do the same things for the Theatres tab. 
     intent = new Intent().setClass(this, BarActivity.class); 
     spec = tabHost.newTabSpec("Weeks").setIndicator("Weeks").setContent(intent); 
     tabHost.addTab(spec); 
+0

我有別這個事情,但寫在這些活動我的代碼被稱爲只有一次當我第一次打開該應用程序。第二次,當我點擊另一個標籤,然後我只是向我展示了它所反映的視圖。我怎麼能再次調用活動..?請指導 – Shah 2011-02-11 06:15:41