tags:

views:

64

answers:

1

I am adding a local database as a cache to a remote web service in my android application to answer queries. I used ArrayAdapters before for list views to display the results from the web service. Now with a database cache, the result could be either a Cursor(from database) or a List(from web), which means the adapter can be CursorAdapter or ArrayAdapter too. Creating two adapters for one query doesn't seem to be a good idea. So I am wondering what would be the best way to refactor my current code to add this database feature?

Thanks,

A: 

You should create a new class that extends from BaseAdapter and add that logic there.

Macarse
Then I would still need two different implementations of this class for cursor and list. I think what is missing here is a common interface for the different data sources that can be fed into the ListAdpater. I am not sure whether this is a good idea, but wrapping a list as a cursor could work here, which makes AbstractCursor this common interface.
wei