简体   繁体   English

Android ContentResolver.query和自定义列

[英]Android ContentResolver.query and Custom Columns

I want to make an Android App that includes a list of audio files with extra info from each file's ID3 tag. 我想制作一个Android应用程序,其中包含音频文件列表以及每个文件的ID3标签提供的额外信息。

I currently use ContentResolver.query to get the audio files. 我目前使用ContentResolver.query来获取音频文件。 The ID3 data I want is not part of the common, queryable information, so once I get the filename I'll need to extract it myself. 我想要的ID3数据不是常见的可查询信息的一部分,因此一旦获得文件名,我就需要自己提取它。

My question is how to add that extra information to the cursor? 我的问题是如何将额外的信息添加到光标? I understand that I can't change the cursor structure. 我了解我无法更改游标结构。 Can I add more columns in advance and fill the data later? 我可以预先添加更多列,然后再填充数据吗? Do I have to clone all the data to a new data structure of my own? 我是否必须将所有数据克隆到自己的新数据结构中?

Itai. 伊泰

It sounds like your are reading audio file information from the built-in media database. 听起来您正在从内置媒体数据库中读取音频文件信息。 In that case there is no way you can add this information to the cursor. 在这种情况下,您无法将此信息添加到光标。

But you can get the extra information in your cursor-reading loop and put it and the information from the cursor into an object that will contain both. 但是,您可以在游标读取循环中获取额外的信息,并将其和游标中的信息放入包含这两者的对象中。

If you are looking to use this with a CursorAdapter to fill a list view, there is no good way to put this information together. 如果要与CursorAdapter一起使用以填充列表视图,则没有很好的方法将这些信息放在一起。

Some possibilities: 一些可能性:

  1. Read the ID3 tag info when you bind the view in your adapter - this means you will be doing extra processing in the UI thread which may slow your app down. 当您在适配器中绑定视图时,请阅读ID3标签信息-这意味着您将在UI线程中进行额外的处理,这可能会使您的应用变慢。

  2. Copy the information from the your cursor to your own database along with the ID3 tag information and read it from there the next time around - this means you will have repeating information of a potentially large size. 将信息与ID3标签信息一起从光标复制到您自己的数据库中,并在下一次从那里读取它-这意味着您将拥有可能很大的重复信息。

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

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