Edited for a little clarity So ... I must be misunderstanding how to properly use TabHosts, because my code crashes completely during setup when I try to add some TabSpecs.. I would like to have a view that has some UI interface with graphics associated with it and animations, and then a menu system that uses a tab setup. My code looks something along the lines of:
public void myView extends RelativeLayout {
// Other Views ...
private TabHost myTabHost;
private ExpandableListView listView1; // content for tab 1
private ExpandableListView listView2; // content for tab 2
public myView(Context context) {
super(context);
// some other stuff
myTabHost = new TabHost(context);
myTabHost.setId(R.id.myTabHost);
listView1 = new ExpandableListView(context);
listView1.setId(R.id.myExpandableListView1);
listView2 = new ExpandableListView(context);
listView2.setId(R.id.myExpandableListView2);
TabSpec tab1 = myTabHost.getTabSpec(res.getString(R.string.tab1));
tab1.setIndicator(res.getString(R.string.tab1), res.getDrawable(R.drawable.tab1));
tab1.setContent(R.id.myExpandableListView1); // *********
myTabHost.addTab(tab1);
// do something similar for tab2..
}
}
Here's the Activity I'm currently using..
public void myActivity extends Activity {
@Override
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
// do a little stuff..
TabHost myTabHost = (TabHost) findViewById(R.id.myTabHost); // not sure if I'm supposed to set up the tabs in my activity, or not..
// I tried it after it crashing in the view, and it still crashed in the activity..
ExpandableListView myListView1 = (ExpandableListView) findViewById(R.id.myExpandableListView1);
// set up expandable list view the way I want from data sources..
// do something similar for myListView2
}
}
From what I understand, I don't want to extend TabActivity because that assumes the whole screen is going to be one giant TabHost, right? I only want the TabHost to be a small portion of the Activity... The problem is that the system crashes where I have indicated by the *********
's.. I guess I just don't understand properly how to go about setting up the tabs? Could someone please enlighten me as to the proper way to do it, or maybe suggest why it's crashing? I guess I should also add the question .. to use a TabHost, do I HAVE to use a TabActivity? (I don't see why I would have to, but Android can be funny that way..)
BONUS I was poking around and found this stackoverflow link regarding tabhosts without tabactivities.. They reference a LocalActivityManager. I'll have to read about that..