好的,我这里有一个相当复杂的小设置。我的主要活动是 a TabHost
,其中一个选项卡显示一些文本、一个按钮,然后是一个ListView
. 出于某种原因,ListView
将只显示 1 个项目。当我添加更多项目时,仅显示列表中的第一个项目。
选项卡菜单.xml:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:configChanges="orientation|keyboardHidden|screenSize">
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:scrollbarStyle="outsideInset"
android:scrollbars="horizontal"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<include layout="@layout/main"/>
<include layout="@layout/scheduler"/>
</FrameLayout>
</LinearLayout>
</TabHost>
</ScrollView>
Scheduler.xml:(这是列表视图所在的位置)
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/schedulerLayout">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop ="true"
android:gravity="center"
android:paddingBottom="20dp"
android:id="@+id/timeLayout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/currentHours"
android:textSize="50dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="50dp"
android:text=":"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/currentMinutes"
android:textSize="50dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ampm"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/currentDayOfWeek"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/currentDate"/>
</LinearLayout>
</LinearLayout>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/scheduleButton"
android:text="@string/newSchedule"
android:layout_below="@id/timeLayout"/>
<!--android:enabled="false"-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/scheduleButton"
android:paddingTop="5dp"
android:orientation="vertical">
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:background="#FFFFFFFF"/>
<ListView
android:id="@+id/scheduler_list_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<!-- android:focusable="false"
android:focusableInTouchMode="false"-->
</LinearLayout>
</RelativeLayout>
主.java:
//adds tabs to view
spec = tabHost.newTabSpec("Auto Respond")
.setIndicator(" Auto Respond ")
.setContent(R.id.mainLayout);
tabHost.addTab(spec);
spec = tabHost.newTabSpec("Scheduler")
.setIndicator(" Scheduler ")
.setContent(R.id.schedulerLayout);
tabHost.addTab(spec);
tabHost.getTabWidget();
//start setup of list display
int number = 0;
ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>();
HashMap<String, Object> row = new HashMap<String, Object>();
//gets number of items, gets title, startTime, etc. here (lots of code, so I cut it out)
if(curTitle != null && !curTitle.equals(""))
{
row = new HashMap<String, Object>();
row.put("Title", curTitle);
row.put("Time", time);
row.put("Day", dayText);
row.put("Month", monthText);
data.add(row);
}
//create list
SimpleAdapter adapter = new SimpleAdapter(this,
data,
R.layout.schedulerow,
new String[] {"Title","Time","Day", "Month"},
new int[] { R.id.scheduleListTitle, R.id.scheduleListTime,R.id.scheduleListDays, R.id.scheduleListMonths});
listview.setAdapter(adapter);
关于为什么它只显示我的第一项的任何想法ListView
?我尝试简单地更改Activity
为ListActivity
FC'd。我真的不想重新编写所有代码以使其作为 . 工作ListActivity
,所以我想尽可能保留它Activity
。