Friday 6 July 2012

List of Android Adapters

Month ago I first saw ResourceCursorAdapter being used in Android development.
That gave me enough curiosity to summarize them all in a single place.


There are several types which differ by data source and manipulation complexity available to the user. Lets start...

BaseAdapter
Simple adapter implementation used for ListView. You provide data by overriding required methods that provide elements for the list. Mostly used for simple list implementations.

SimpleAdapter 
Very useful adapter that allows us to map data to elements in the layout file. You provide a grid (two same sized arrays) which tells which element goes into which place and map that contains all the data needed for this grid to know what to put where.

ArrayAdapter
For me less convenient than the SimpleAdapter since default behavior is to map String array elements to single text field. You can override it and provide an array of complex object which have data to populate more complex rows.

SimpleCursorAdapter
An easy adapter to map columns from a cursor to elements defined  in the layout file. You can specify which columns you want, which views you want to display the columns, and the layout file that defines the appearance of these views.


CursorAdapter
More sofisitcated implementation of the SimpleCursorAdapter which is abstract so its up to you
to create views with cursor providing you the data from database.

ResourceCursorAdapter
Very similar to CursorAdapter. Doesn't have a newView method which makes it more appropriate
for not so complex views. 

SpinnerAdapter
Haven't used this one that much but from what I've seen enables you to define two views, one with data and the second dropdown with choices.

SimpleCursorTreeAdapter
The following two are my most favorite. They allow us to define list elements together with the groups they belong in. Very convenient for situations where you need list with grouped data. You provide both child and group views with appropriate data binding

CursorTreeAdapter
Same as previous but with more liberty and requirements. Better for complex lists.

HeaderViewListAdapter
ListAdapter used when a ListView has header views. This ListAdapter wraps another one and also keeps track of the header views and their associated data objects.

WrapperListAdapter
Haven't seen this one before. Haven't seen any examples but it seems it wraps another list adapter. Strange...

Well that's all I thing....
Now I have them all in single place so I don't have to look around. Sweet :)


11 comments:

  1. Nice copy/paste of the documentation ..

    ReplyDelete
  2. Thanks for sharing (Y) ..Must cover ExpandableListAdapter & SimpleExpandableListAdapter also..:)

    ReplyDelete
  3. What adapter is more appropriate for nested listview? thanks

    ReplyDelete
  4. I think ExpandableListAdapter should do the trick

    ReplyDelete
  5. nice info and some of them even new for me. i have never even heard about it.
    Thanks.

    ReplyDelete
  6. Thanks for sharing about list of android adapter..Android Training in chennai

    ReplyDelete
  7. Happy to see this blog i got the solution wat i needed Android Training

    ReplyDelete