Cursor with result from multiple content providers - Android
I want to query two different content providers:
MediaStore.Images.Media.EXTERNAL_CONTENT_URI
and
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI
First I need to query the "MediaStore.Images.Media.EXTERNAL_CONTENT_URI" so that I can get a cursor to all images that were added after a specific date. I know now how to do this. The problem is with the thumbnails. I also need to query the "MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI" for obtaining the thumbnail images so that I can show them in a listview. This is were I somehow need to combine the result from the two queries because I only want the Thumbnails for the Images that were added after a specific date. But the "MediaStore.Images.Thumbnails" doesn't have information about when the image was added. It only has an ID to the original image in "MediaStore.Images.Media".
So, to sum up what I need help with:
I need to get a cursor that contains the following columns:
MediaStore.Images.Thumbnails.IMAGE_ID,
MediaStore.Images.Thumbnails._ID,
MediaStore.Images.Thumbnails.DATA,
MediaStore.Images.Media.DATA,
MediaStore.Images.Medi开发者_StackOverflow社区a.DATE_TAKEN
How can this be done?
Thanks for help!
You can select the data from one provider, and select per row using a ViewBinder.
Within MyActivity.onCreate() {
...
cursorAdapter.setViewBinder(myViewBinder),
...
}
And somewhere you implement your ViewBinder like this...
private final ViewBinder myViewBinder=new ViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if(columnIndex==INDEX_OF_THUMB) {
int id=cursor.get("_id");
// get thumb-image data for id from somewhere
// and display in view
}
};
Hope this helps.
AFAIK, you will manually need to do the join and pour the results into a MatrixCursor
(if you are sure that you really need a Cursor
) or some other data structure.
精彩评论