2011-05-06 70 views
1

我有一个TabHost有两个选项卡。每个标签都有自己的意图:如何确定当前选定的选项卡?

TabHost.TabSpec spec; // Resusable TabSpec for each tab 
     Intent intent; // Reusable Intent for each tab 

     // Create an Intent to launch an Activity for the tab (to be reused) 
     intent = new Intent().setClass(this, ARActivity.class); 

     // Initialize a TabSpec for each tab and add it to the TabHost 
     spec = tabHost.newTabSpec("trending").setIndicator("Trending",res.getDrawable(R.drawable.icon)).setContent(intent); 
     tabHost.addTab(spec); 

     // Do the same for the other tabs 
     intent = new Intent().setClass(this, WatchlistActivity.class); 
     spec = tabHost.newTabSpec("watchlist").setIndicator("Watchlist",res.getDrawable(R.drawable.icon)).setContent(intent); 
     tabHost.addTab(spec); 

     tabHost.setCurrentTab(0); 

如何确定哪个选项卡时,我在ARActivity或当我在WatchlistActivity选择?

回答

1

嗨,你可以使用tabHost.getCurrentTab()onResume()这两个活动来检测你选择了哪个标签。

+0

但在活动中我没有参考tabHost ... – 2011-05-06 18:51:33

相关问题