简体   繁体   English

来自多个内容提供商的结果的游标 - Android

[英]Cursor with result from multiple content providers - Android

I want to query two different content providers: 我想查询两个不同的内容提供者:

MediaStore.Images.Media.EXTERNAL_CONTENT_URI MediaStore.Images.Media.EXTERNAL_CONTENT_URI

and

MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI 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. 首先,我需要查询“MediaStore.Images.Media.EXTERNAL_CONTENT_URI”,以便我可以将光标移动到特定日期之后添加的所有图像。 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. 我还需要查询“MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI”以获取缩略图图像,以便我可以在列表视图中显示它们。 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. 但是“MediaStore.Images.Thumbnails”没有关于何时添加图像的信息。 It only has an ID to the original image in "MediaStore.Images.Media". 它只有“MediaStore.Images.Media”中原始图像的ID。

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.IMAGE_ID,

MediaStore.Images.Thumbnails._ID, MediaStore.Images.Thumbnails._ID,

MediaStore.Images.Thumbnails.DATA, MediaStore.Images.Thumbnails.DATA,

MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATA,

MediaStore.Images.Media.DATE_TAKEN MediaStore.Images.Media.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. 您可以从一个提供程序中选择数据,然后使用ViewBinder选择每行。

Within MyActivity.onCreate() {
...
cursorAdapter.setViewBinder(myViewBinder),
...
}

And somewhere you implement your ViewBinder like this... 在某个地方你实现了像这样的ViewBinder ......

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,您将手动需要进行连接并将结果倒入MatrixCursor (如果您确定需要Cursor )或其他一些数据结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM