Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何编写Like语句在我的特殊文件夹上创建光标?_Android_Cursor_Directory_Mediastore - Fatal编程技术网

Android 如何编写Like语句在我的特殊文件夹上创建光标?

Android 如何编写Like语句在我的特殊文件夹上创建光标?,android,cursor,directory,mediastore,Android,Cursor,Directory,Mediastore,我正在为android编程,我已经在SD卡上获得了所有音频详细信息。我有一个问题: 如何编写Like语句在我的特殊文件夹上创建光标? 我不希望游标访问所有外部文件。只在我的文件夹上。我希望限制游标。但是如何?使用哪种方式,如Statemet Cursor audioCursor = ((Activity)context ). managedQuery(audiosUri,star,MediaStore.Audio.Media.DATA + " LIKE ?", new String[] { f

我正在为android编程,我已经在SD卡上获得了所有音频详细信息。我有一个问题:

如何编写Like语句在我的特殊文件夹上创建光标? 我不希望游标访问所有外部文件。只在我的文件夹上。我希望限制游标。但是如何?使用哪种方式,如Statemet

 Cursor audioCursor = ((Activity)context ). managedQuery(audiosUri,star,MediaStore.Audio.Media.DATA + " LIKE ?", new String[] { folderpath }, null);   

我就是这样做的。当用户长时间单击时,将对音乐数据库执行查询_数据保存每个歌曲的完全限定路径,因此查询将返回该文件夹中的所有文件。 path是path=newarraylist();它是由path.add(file.getPath())构建的; 您将发现许多关于如何显示文件夹和文件的示例

    ListView lv = getListView();
    lv.setOnItemLongClickListener(new OnItemLongClickListener() {

        public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
                int row, long arg3) {
            String criteria = path.get(row);
            int criterialength = criteria.length();
            int lastslash = criteria.lastIndexOf("/");
            String suggestedname = criteria.substring(lastslash + 1,
                    criterialength);
            String where = MediaStore.Audio.Media.DATA + " like ?";
            criteria = "%" + criteria + "%";// looking for path string in
                                            // DATA of database
        // now get your cursor similar to shown below and do something with it
            return true;
        }
    });


public Cursor getCriteriacursor(Context context, Cursor cursor,
        String where, String criteria) {
    ContentResolver cr = context.getContentResolver();
    String[] strcriteria = { criteria };
    final String[] columns = { track_id, track_no, artist, track_name,
            album, duration, year, composer };
    cursor = cr.query(uri, columns, where, strcriteria, null);
    return cursor;
}
ListView lv=getListView();
lv.setOnItemLongClickListener(新的OnItemLongClickListener(){
长单击(AdapterView arg0、视图arg1、,
int行,长arg3){
字符串条件=path.get(行);
int criterialength=criteria.length();
int lastsslash=criteria.lastIndexOf(“/”);
String suggestedname=criteria.substring(lastslash+1,
标准长度);
字符串,其中=MediaStore.Audio.Media.DATA+“like?”;
criteria=“%”+criteria+“%”;//在中查找路径字符串
//数据库数据
//现在,让您的光标与下图类似,并对其进行处理
返回true;
}
});
公共游标getCriteriacursor(上下文上下文、游标游标、,
字符串(其中,字符串条件){
ContentResolver cr=context.getContentResolver();
字符串[]strcriteria={criteria};
最终字符串[]列={track\u id,track\u no,artist,track\u name,
专辑,持续时间,年份,作曲家};
cursor=cr.query(uri、列、其中、strcriteria、null);
返回光标;
}

为什么光标没有关闭??不应该关闭它吗?一旦使用它,您就可以关闭它。通常,一旦您选择了文件夹,您将按游标循环。movefirst()、cursor.movenext()等。当您不再需要此游标时,请关闭它cursor.close()和我以前使用过的from cursor。我以前只使用过from cursor。我需要一个类似的语句。使用“从ContentResolver”而不是我在问题中为代码编写的工具会更好。我还没有测试你的代码,但是如果你确定你的代码可以更正和使用,请与我联系,接受你的答案。我只需要一个类似的语句。无论如何,谢谢亲爱的。。。