views:

1190

answers:

2

Im pulling a list of product objects from a database call and I want to build a ListView of the data in my activity with a non-scrolling header and footer. Each row will consist of a product thumbnail, some data and a button arranged horizontally. I understand that using the ListView I can inflate each row using a separate layout.

Most of the examples Ive seen using ListView just show a simple array of strings that fill the whole view of the activity, but most real-world examples will be more complex and I can't find any good examples that explain how all these pieces fit together.

Does anyone have any pointers to sample code with a good explanation ?

+2  A: 

The easiest way to have a complex row in a ListView is via a SimpleAdapter. There are a number of examples around for that, for example.

To force the ListView to fill the remaining portion of the screen, set the properties as follows:

Use a LinearLayout.

On the list view:

android:layout_height="fill_parent",
android:height="0dp",
android:layout_weight="1"

On all other widgets:

android:layout_height="wrap_content"

Do not set a height or layout_weight

Mayra
Another example that doesn't show the main layout XML either. Normally an application will have a header, a list of items and maybe some more widgets near the bottom. Not sure how to have the bottom widgets stay at the bottom and not take over the whole parent. I want the list view to expand to fill the space between the header and footer widgets but after that it should just scroll without affecting the them.
Eno
I missed that part of the question, see edits.
Mayra
+3  A: 

Two examples that helped me a lot:

http://www.codemobiles.com/forum/viewtopic.php?t=876

and

http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html

i hope they are usefull to you.

Andy