2011-02-11 21 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