是否可以使用where条件将Mediastore游标设置为Rowset中的特定行?

问题描述 投票:0回答:1

我想将光标设置到行集中的特定行,而不过滤行集。有没有一种方法可以将光标移动到行集中的何处?目前我的解决方案是

// search for a _ID
if (cur != null) {       // my row set
        int idColumn = cur.getColumnIndex(MediaStore.Images.Media._ID);
        cur.moveToFirst();
        do {
            if (search_id == cur.getInt(idColumn))) // row found
                return;                      // ok, cursor in right position
        } while (cur.moveToNext());
        cur.moveToFirst();                    // id not found
}

预先感谢

java android sqlite kotlin mediastore
1个回答
0
投票

[不能不遍历游标,除非您事先知道位置,在这种情况下,您可以使用cur.moveToPosition(integer_posisition)(顾名思义,其中integer_position表示行)在游标中的位置,请注意第一行是row 0,而不是1。

当然,如果要搜索特定的行,通常将使用WHERE子句使用查询来仅检索该行。

© www.soinside.com 2019 - 2024. All rights reserved.