mardi 29 septembre 2015

Change adapter based on sort criteria

I'm building an application which needs to perform http request or sql request based on a sort criteria.

When the sort criteria is Popularity or Vote I call an API. When the criteria is Favorite I use a SQLite database.

I currently have a custom adapter which extends BaseAdapter to fetch data from http request. I also use this adapter for sql request but I have to manually rerun the sql request and notify the adapter on changes.

For sql request, I would like to use a cursor adapter in order to easily use some features like loaders.

My question is : Is it possible / Is it a good practice to have two adapters and to switch them based on sort criteria ?

If no, what should I do ? I have some ideas like build a custom AsyncTaskLoader or save the http results into the database with a isFavorite entry so I will be able to only use the CursorAdapter.

Aucun commentaire:

Enregistrer un commentaire