views:

92

answers:

3

I am using a listview to display items. Currently I am passing an String array of items to it. But I want to pass one more array and display its items alongwith the items of the first array(i.e somehow two lines of text). How can I do that?

A: 

Use a table or format the items of the various arrays into a new array.

Aaron Digulla
+3  A: 

Hi!
You could also make a custom Adapter for your list and use custom class as type of items of that adapter. Something like this:


class CustomAdapter extends ArrayAdapter < RowData > {
   ...
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
        ...
        }
}

class RowData {
   String line1;
   String line2
   RowData(String l1, String l2){line1=l1;line2=l2;}
}

Regards!

Ramps
+1  A: 

Since both the arrays contain data to be displayed in a row of a listview, IMO it is logical and fair to believe that they are related in some manner.
You can create a class called RowData and have a String(data type of first array) and Object(or datatype of second array) as its members. You can then pass an array of Rowdata type to the list view.
For instance, if you want to pass: String[] and Date[] to the listView you will pass RowData[] now, where Rowdata is defined as:

class RowData{ 
String dataItem1; 
Date dataItem2;
}
Samuh