I have a form with a number of EditView fields in it. The data for these fields are loaded from a database (in the onCreate() method). The last object on the screen should be a ListView that should show all related data records to the record being show. All the data is correctly loading, and the adapter for this seems to work ok. It loads the correct data, it formats the data correctly into the two-line layout specified by the .xml used by the adapter.
The problem is that the ListView on the screen is "shrunk" to show only one item, and adds a scrollbar if there's more items. I expected the ListView to expand in size to show all records, and the screen itself being scrollable (everything is wrapped inside a ScrollView).
So, the XML looks like this:
<ScrollView
android:layout_height="wrap_content"
android:id="@+id/ScrollView1">
<RelativeLayout
android:layout_height="wrap_content"
android:id="@+id/RelativeLayout1">
<EditView
android:id="@+id/EditView1>
</EditView>
<ListView
android:id="@+id/ListView1
android:layout_height="wrap_content"
android:layout_below="@id/EditView1>
android:divider="#b5b5b5"
android:dividerHeight="1dp" />
I then use a custom BaseAdapter to fill data into the ListView
listView = (ListView) findViewById(R.id.ListView1);
dbRecords = db.getAllRecordsByRecordId(recordId);
CBA_Records adapter = new CBA_Records(this, dbRecords);
listView.setAdapter(adapter);
This is all the same stuff that I've done before, except this is all wrapped inside the scrollview. The reason for this is that there might be more fields than will fit on a smaller screen (or horizontal screen), so the screen must be scrollable. And, the listview must also be there ...
Any suggestions?
A little more onto what invertigo said. ListView
inside a ScrollView
is not recommended.
Make your ListView
the root, and set it's width and height to "match_parent"
. Put the other stuff that's above the ListView
(the header) in a separate xml. Then inflate the new xml file for the header use the addHeaderView()
method to add it as a header to the ListView
(it looks like you want everything to scroll).