Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - How do you bind a ListView to a collection of custom objects?

I've got a class called PhoneContact with 3 properties: Title, Description and PhoneNumber

If I have a collection of these, how would I go about binding these to a ListView containing a TextView for each property?

like image 234
Tristan Warner-Smith Avatar asked Feb 23 '10 13:02

Tristan Warner-Smith


1 Answers

Extend ArrayAdapter, overriding the getView(int, View, ViewGroup).

To hook up your custom adapter, I'll assume your Activity extends ListActivity. In one of the lifecycle methods (such as onCreate(), onResume(), or onStart()), call setListAdapter(myCustomAdapter).

This article shows how to do it: Android Series: Custom ListView items and adapters.

like image 175
Eric Burke Avatar answered Oct 12 '22 13:10

Eric Burke