Currently I have a TabHost implemented with 3 tabs each containing a separate activity. My question is how do I switch between tabs from within one of the activities that is located inside the tab host. I’ve looked everywhere and have been unsuccessful in finding a real answer to this problem.
Currently I have a TabHost implemented with 3 tabs each containing a separate activity.
Share
After a long time of battling with this problem I’ve been able to find a solution to switching tabs when using activity based tabs.
In the parent activity class where the tabhost is created I implemented a method like the one below:
Inside of the tab that I would like to be able to switch internally to another tab I created the method below:
If you would like a good example of this code, you can take a look at my MintTrack project here and here.
As a side note, please be very careful when deciding whether to use view or activity based TabHost.
Activitybased tabs are great because they can be separated into there own XML file. Activities can also be organized into there own Java file instead of being cluttered into one. That being said some of the things you would think would be easy become complicated with activity based tabs. Its hard to pass information between tabs without creating overhead.Activitybased tabs also use more memory/CPU time as they have the overhead of theActivityaround each of them. Please consider this and the many more trade offs before diving into using anActivitybasedTabHost. I know now that I would personally go with a view basedTabHostif I ever used them again.