【发布时间】:2011-06-09 19:13:44
【问题描述】:
为清晰起见进行了编辑 所以......我一定是误解了如何正确使用 TabHosts,因为当我尝试添加一些 TabSpecs 时,我的代码在设置过程中完全崩溃了。然后是使用选项卡设置的菜单系统。我的代码看起来类似于:
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..
}
}
这是我目前正在使用的 Activity..
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
}
}
据我了解,我不想扩展 TabActivity,因为这假设整个屏幕将是一个巨大的 TabHost,对吗?我只希望 TabHost 成为 Activity 的一小部分...问题是系统崩溃了我用********* 表示的地方。我想我只是不明白如何进行设置上标签?有人可以告诉我正确的方法吗,或者建议为什么它会崩溃?我想我还应该添加问题..要使用 TabHost,我必须使用 TabActivity 吗? (我不明白为什么我必须这样做,但 Android 可能会很有趣..)
奖金 我四处寻找,发现这个stackoverflow 链接关于没有tabactivities 的tabhosts。他们引用了LocalActivityManager。我得去读一读。。
【问题讨论】: