Set a Tab from an activity
I have a TabActivity and inside 5 tabs with 5 activities each one. I want to set one of my tabs but not from the TabActivity(clicking on the tab on the top) but from an activity of any tab, for example click开发者_如何学Going on a button of activity 3(which is asociated with the 3rd tab).
In my TabActivity there is a variable mTabhost
, which I can use to set the selected tab with
mTabHost.setCurrentTab(0);//home
I guess I need access to that variable from Activity1-2-3-4, and doing that variable static doesnt work.
Say you have a MyTabActivity
as TabActivity
, which hosts 5 Activity
(ies).
If you want to change the Tabs inside SecondActivity
, you would write the code something like this.
MyTabActivity myTabs = (MyTabActivity) this.getParent();
Here you have your MyTabActvity you can change the tabs like:
myTabs.getTabHost().setCurrentTab(index);
Save this mHost var instance in singleton class say Utility class . Then access particular var from Utility Class in different activity and set it accordingly. It works. I 've used it in my several projects.
精彩评论