Androider
Androider

Reputation: 21345

Best ListViewAdapter for multiple row types?

I need to implement a ListAdapter for multiple row types. So pick a layout per row based on the content of that row. I would like to hear some opinions on the merits of the different types of ListAdapters for accomplishing this. I don't expect to have thousands of rows or even a hundred, but I may potentially have quite a few different layouts and need a flexible easy to understand implementation.

So I am considering

BaseAdapter

ArrayAdapter

CursorAdapter

SimpleCursorAdapter

What are some of the advantages/disadvantages of these adapters. Would a cursor based adapter be better?

I want a it to be flexible, easy to change and work reliably.

Upvotes: 1

Views: 957

Answers (1)

Bert F
Bert F

Reputation: 87543

The adapters are there to adapt a data source to the view, so it really comes down to your data source.

  • If its a database data source and you have largely straight-froward mappings of columns to text and image views, start with SimpleCursorAdapter.

  • If its a database data source but a lot of custom mappings or if you end up overriding a lot of SimpleCursorAdapter's functionality anyway, take a look at CursorAdapter.

  • If the data source is something that can viewed as an array, the look at ArrayAdapter.

  • If its a custom data source or if there's a alot of custom logic for binding the data to the views that doesn't fit the other adapters, derive your own adapter from BaseAdapter.

Upvotes: 3

Related Questions