tags:

views:

48

answers:

1

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 :)

+1  A: 

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().

CommonsWare
A side note, as i mentioned i was doing this, but i did not mention it was crashing.I found out by randomly strolling through the various other functions of TabHost, but it seems setup *needs* to be called. It is automatically called if you use a TabActivity, but other wise you need to call it yourself.I'll make a note in my question for future viewers. Sorry for not providing the crucial detail to my issue :)Thanks!
Lee Olayvar