开发者

How to pass more than one array to a listview?

I am using a ListView to display items. Currently I am passing a String array of items to it. B开发者_Python百科ut I want to pass one more array and display its items along with the items of the first array; that is, somehow having two lines of text.

How can I do that?


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!


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;
}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜