Reputation: 701
Please help me out here. I need to make a list view as shown in the sample pic for my android app. How to do it? Also I need to add image along it as seen in the sample pic. and link it to another view to show some more details.please check links shown below.
Upvotes: 1
Views: 1725
Reputation: 104198
You need to implement a BaseAdapter. BaseAdapter defines a getView method, which will return the view that will be used by the list items. You can create the view diagrammatically or load it from XML. Then in your ListActivity you use the setListAdapter method.
See an example here.
Upvotes: 0
Reputation: 24472
First create a layout for your list item in layout/list_item.xml (or any name). I've shown only text field for the item, but you can change the view below to include both image and a label.
<TextView xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:textSize="14dp"
a:paddingBottom="5dp"
a:paddingTop="5dp">
</TextView>
Define a listView in another layout e.g. layout/list.xml
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="fill_parent"
a:layout_height="fill_parent"
a:orientation="vertical"
a:stretchColumns="1">
<ListView a:id="@+id/paramList" a:layout_width="fill_parent"
a:layout_height="fill_parent" />
</LinearLayout>
In your activity get the handle to list view and add data to it.
// Find the list view component in your layout.
ListView list = (ListView) findViewById(R.id.paramList);
// obtain data
List data = ... //some list data
// use a list adapter to render your list item in your list view!!
// The item is rendered using the list_item.xml layout.
// Here you can have any layout, with image and text as in your pic.
ListAdapter adapter = new ArrayAdapter(this, R.layout.list_item, data);
list.setAdapter(adapter);
Upvotes: 3