Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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.

MyTabActivitymyTabs= (MyTabActivity) this.getParent();

Here you have your MyTabActvity you can change the tabs like:

myTabs.getTabHost().setCurrentTab(index);

Solution 2:

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.

Post a Comment for "Set A Tab From An Activity"