Lee Olayvar
Lee Olayvar

Reputation: 3810

How to retrieve the TabHost object, if you're not using TabActivity?

I am attempting to use a few of the simple android examples for Tab Views. One thing i am attempting to do different than all the examples i've seen so far, is to not use a TabActivity. I am trying to use a normal activity, which means i need to retrieve the TabHost object some how, so i can add tabs and etc to it. How can this be done?

If you wanted to retrieve a view, you can simply use findViewById(R.id.blah), but how can you retrieve the TabHost object in a similar manner?

EDIT: So CommonsWare provided the answer to the question i was asking, but i had not stated my problem it seems. I was using findViewById, and casting it as a TabHost, ala TabHost tab_host = (TabHost)this.findViewById(R.id.mytabhost);, but whenever i used it the application would crash.

The problem is if you are not using TabActivity, TabHost.setup() is never called, so you need to yourself.

This issue is now resolved :)

Upvotes: 0

Views: 582

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006584

How can this be done?

Call findViewById().

If you wanted to retrieve a view, you can simply use findViewById(R.id.blah), but how can you retrieve the TabHost object in a similar manner?

A TabHost is a View. You find it by calling findViewById().

Upvotes: 1

Related Questions