Android的MediaStore与TITLE_KEY比较得到的光标位置 [英] Android MediaStore get cursor position by comparing with TITLE_KEY
问题描述
我使用MediaStore的媒体内容,并有一个搜索查看过滤在listfragment显示的内容。
I am using MediaStore's media content and have a SearchView to filter the content displayed in a listfragment.
我把(
当用户搜索,我得到基于查询新的光标
I keep a reference to the cursor(mainCursor
) when the query string is null (which means all rows)
When user searches, i get new cursor based on the query
按我的理解(我很新的光标,DB&安培; ContentProvider的),光标将包含匹配查询和列查询所有行是 MediaStore.Audio.Media.TITLE
,这样我就可以看到列表匹配的标题。
As per my understanding(I am very new to Cursor,DB & Contentprovider), the cursor will contain all the rows matching the query and the column to query is MediaStore.Audio.Media.TITLE
, so i can see matching titles in list.
public void doQuery(String query) {
// TODO Auto-generated method stub
Log.e(TAG,"inside doQuery: "+query);
String search = MediaStore.Audio.Media.TITLE + " LIKE '%" + query + "%'";
Cursor cursorNew = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,columns, search , null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
sendBroadcast(new Intent(MainActivity.SWAP_CURSOR));
}
现在,当用户presses列表元素,I 为getPosition()
光标并检索 TRACK_ID
的选择的项目。
Now when user presses list element, i getPosition()
of the cursor and retrieve the TRACK_ID
of selected item.
我的问题是:如何寻找最初的光标,即 mainCursor
与 TRACK_ID
从获得 cursorNew
和来获得mainCursor匹配TRACK_ID的位置?
我不想 SELECT
从mainCursor,因为我想从非过滤的光标获取特定轨道的位置
My question is: How to search the initial cursor, i.e., mainCursor
with TRACK_ID
got from cursorNew
and to get the position of the matching TRACK_ID in mainCursor?
I don't want to SELECT
from the mainCursor, because i want to get the position of a specific TRACK from the un-filtered cursor
在此先感谢
推荐答案
如果你在的位置有兴趣,你为什么不把audio_ids阵列中的
If you are just interested in the position, why dont you put the audio_ids in an array
ArrayList<String> audio_ids = new ArrayList<String>();
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()){
String audio_id = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Playlists.Members.AUDIO_ID));
audio_ids.add(audio_id);
}
,然后用
String audio_id = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Playlists.Members.AUDIO_ID));
position = audio_ids.lastIndexOf(audio_id);
此示例查询播放列表。上面的例子能给你的最后一个位置,如果你有重复。 (你也许没有想过?)
我希望这给你一些想法
This example queries playlists. The above example would give you the last position if you had duplicates. (something you perhaps had not thought about?) I hope this gives you some ideas
这篇关于Android的MediaStore与TITLE_KEY比较得到的光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!