OK, I’ve got a quite complex little setup here. My main activity is a TabHost, and one of those tabs displays some text, a button, and then a ListView. For some reason, the ListView will only show 1 item. When I add more items, only the first one in the list shows.
tabmenu.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: (This is where the listview is)
<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>
Main.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);
Any ideas as to why it only shows the first item in my ListView? I tried simply changing Activity to ListActivity and it FC’d. I don’t really want to re-do all of my code to make it work as a ListActivity, so I want to keep it as Activity if possible.
You are trying to display a lot of information and you have nested your ListView in a ScrollView… Do you have to scroll to see the ListView?
Nesting two scrollable Views usually doesn’t work because, in this case, the ListView consumes the gestures preventing the ScrollView from scrolling which in turn prevents you from seeing the entire ListView.