swalkner
swalkner

Reputation: 17339

Android: Change View of Tab

I've got a TabHost with three tabs; each holding one activity.

I'd like to change the view of one tab to another view - how can I do that programatically? I don't like to use ActivityGroups, as I've experienced several problems with ActivityGroups.

It would be perfect if I could add a View on top of the current one, so the back button is working, too (or at least I could fetch the back button and remove the topmost view).

Upvotes: 2

Views: 3356

Answers (1)

Timo Ohr
Timo Ohr

Reputation: 7947

The content view of the current tab is a child of the layout which you gave the @android:id/content id. You should be able to access it using http://developer.android.com/reference/android/widget/TabHost.html#getTabContentView().

There you can basically add or remove views as you wish.

The content views of inactive tabs are not publicly accessible, and might not be created yet if the tab wasn't selected previously.

Keep in mind that TabHost doesn't actually use Activities, it just turns them into views.

You'd have to implement the back button yourself, though.

Upvotes: 2

Related Questions