TabHost不显示在开始内容 [英] TabHost not showing contents in the beginning
问题描述
我有两个选项卡的TabActivity。活动的布置如下:
I have a TabActivity with two tabs. the layout of the activity is as follows:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="5dp">
<ListView android:id="@+id/list"
android:layout_width="fill_parent" android:layout_height="fill_parent" />
</FrameLayout>
</LinearLayout>
</TabHost>
布局由它在setOnTabChangedListener相应填充(一个ListView的)。带馅的名单,并将其显示没有问题。
The layout consists of a ListView which is populated accordingly in setOnTabChangedListener(). no problem with filling the list and showing it.
我的问题是,在活动开始时不显示列表视图,虽然我通过ID找到它,并填充它;它更改标签后才能填充。
My problem is that the list view is not shown when the activity starts, although I find it by ID and populate it; it is only populated after I change the tabs.
和在OnCreate(..)在code是这样的:
and the code in the onCreate(..) looks like this:
l = (ListView) findViewById(R.id.list);
l.setAdapter(new CommentsAdapter(this, (JSONArray) obj));
TabSpec spec;
spec = tabHost.newTabSpec("0").setIndicator("0",
res.getDrawable(R.drawable.tab_recent)).setContent(
R.id.list);
tabHost.addTab(spec);
spec = tabHost.newTabSpec("1").setIndicator("1",
res.getDrawable(R.drawable.tab_pop)).setContent(
R.id.list);
tabHost.addTab(spec);
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
int tab = Integer.valueOf(tabId);
showDialog(WAIT_DIALOG);
switch (tab) {
// recent
case 0:
//refill the list
break;
// popular
case 1:
//refill the list
break;
}
}
});
tabHost.setCurrentTab(0);
任何提示?
推荐答案
我有一个类似的问题。我注意到的是,如果你做
I had a similar issue. What I noticed is that if you do
tabHost.setCurrentTab(0);
然后 onTabChanged
不会被触发。但是,如果你做
then onTabChanged
is not triggered. BUT, if you do
tabHost.setCurrentTab(1);
那么它就是,在列表中显示,所有它的罚款。按照之所以出现这种情况,它仍然是一个有点谜给我。
then it is, the list shows up and all it's fine. As per why this happens, it remains a bit of a mistery to me.
使用此作弊,开始第一个选项卡上的应用:
在OnCreate()中,您已经创建后,标签先打电话:
tabHost.setCurrentTab(1);
然后调用:
tabHost.setCurrentTab(0);
Use this cheat to start your app on the first tab: in onCreate(), after you've created the tabs call first: tabHost.setCurrentTab(1); Then call: tabHost.setCurrentTab(0);
这篇关于TabHost不显示在开始内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!