Reputation: 175
I made a tabHost in an Activty and everytime it reaches the .addTab(Spec) it crashes. I created the tab host in the Activity like so:
peopleTabHost = new TabHost(this);
and then I use a method to add the tab (I can do that because I defined the peopleTabHost as final outside of the onCreat)
private void CreateNewTab(String tagName, String displayedName, Class<?> intentClass)
{
Intent intent = new Intent().setClass(this, intentClass);
TabHost.TabSpec spec = peopleTabHost.newTabSpec(tagName).setIndicator(displayedName);
spec.setContent(intent);
peopleTabHost.addTab(spec);
}
Thanks
Upvotes: 0
Views: 225
Reputation: 2232
I second sianis' answer, but I'm also adding that it might be crashing because you are not initializing (or at least not showing) the tabhost.
Try to run peopleTabHost.setup();
right after calling the constructor.
Upvotes: 1
Reputation: 598
Why don't you use TabActivity? It is a class which extends ActivityGroup which extends Activity. So you can use a child of TabActivity class like a simple Activity, but it has some more functionality.
Upvotes: 0