1

I have a list view with following row template.

<?xml version="1.0" encoding="utf-8"?>
<!-- row.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:orientation="horizontal">
    <RelativeLayout android:clickable="true"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:background="@drawable/android_btn_large" android:gravity="center_vertical"
        android:layout_weight="1">
        <TextView android:id="@+id/txtLeftButton" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_toRightOf="@+id/imgLeftButton"
            android:text="Riverside Park" android:textColor="#FFFFFF"
            android:layout_alignParentLeft="true"></TextView>
        <ImageView android:id="@id/imgLeftButton" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_toLeftOf="@id/txtLeftButton"
            android:layout_alignParentLeft="true" android:layout_centerVertical="true"
            android:layout_alignParentRight="true" android:src="@drawable/plus_icon_480">
        </ImageView>
    </RelativeLayout>
    <RelativeLayout android:clickable="true"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:background="@drawable/android_btn_large" android:gravity="center_vertical"
        android:layout_weight="1">
        <TextView android:id="@+id/txtRightButton" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_toRightOf="@+id/imgRightButton"
            android:text="Riverside Park" android:textColor="#FFFFFF"
            android:layout_alignParentLeft="true"></TextView>
        <ImageView android:id="@id/imgRightButton" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_toLeftOf="@id/txtRightButton"
            android:layout_alignParentLeft="true" android:layout_centerVertical="true"
            android:layout_alignParentRight="true" android:src="@drawable/plus_icon_480">
        </ImageView>
    </RelativeLayout>
</LinearLayout>

And the data is stored in a List as...

List<String[]> rows = new ArrayList<String[]>();
rows.add(new String[] { "id", "name" });

I want to know what Adapter I should use to fill the ListView with these rows assuming I need 2 column data in a single row?

2 Answers 2

1

Just use a SimpleAdapter with a list of HashMap

ListView list = (ListView) findViewById(R.id.ListView01);

ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();

HashMap<String, String> map = new HashMap<String, String>();
map.put("id", "1");
map.put("name", "bob");
mylist.add(map);

//Each row is a new hashmap
map = new HashMap<String, String>();          
map.put("id", "2");
map.put("name", "sally");
mylist.add(map);

//ect...

mSchedule = new SimpleAdapter(this, mylist, R.layout.listrow,
            new String[] {"id", "name"}, new int[] {R.id.txtID, R.id.txtName});
list.setAdapter(mSchedule)
Sign up to request clarification or add additional context in comments.

3 Comments

I meant 2 rows from rows collection must be filled in a single ListView row.
Assume I can't change collection or rows.
I'm not sure I understand, the method I posted puts 2 (or more) columns of data in a single row
0

You could implement the ListViewAdapter interface in a class and inflate the row-xml in the getView-method. You can use a regular activity with a simple LinearLayout and a list view in it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.