我有两个选项卡的TabActivity。活动的布置如下:TabHost在开头没有显示内容
<?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的。填写清单并显示它没有问题。
我的问题是,活动开始时不显示列表视图,虽然我通过ID找到它并填充它;它只是在我更改标签后填充。
,并在OnCreate(..)的代码如下所示:
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);
任何提示?
就可以把标签的所有代码,使我们可以有外观和告诉 – Sumant 2011-04-10 12:58:59
只是把Java代码及新界XML堂妹乌尔XML可能被罚款ontab更改列表视图是显示 – Sumant 2011-04-10 13:13:04