Search code examples
androidandroid-tabhosttabactivity

Add/Remove Tab and its content from tabhost


I have nine tabs(say 0 to 8), displaying only five tabs on screen. The five tabs will be 0 to 3 of those nine tabs and fifth tab will be MORE Tab. MORE tab will show Activity with GridView showing Image+Title of remaining nine tabs(say 4 to 8). Now on click of any item(Image+Title) in GridView will replace the MORE Tab Image+Title and its content/activity with its respective activity.

I am able to replace the tab indicators(Image+Title) but struggling on replace its respective content/activity.

As on other similar thread they had suggested to use clearAllTabs and add/recreate require tabs again. But i feel clearing all tabs just to replace one tab is heavy.

I am using the TabActivity with Intents. As i know TabActivity is deprecated by its old app initially it had only 5 tabs but now requirement is to add few more tabs.

Need your help to implement this. If it not possible with TabActivity, then switching to fragment tabs does it help me?

I trying to implemtent this Image


Solution

  • I would recommend fragments for sure. I've used TabHost in the past and it was very problematic.

    You can simply have Button at the top that control the visibility of the fragment below. With this way, you'll even be able to add transitions.

    This link give a little more information on that topic. Separate Back Stack for each tab in Android using Fragments