Android在记录中向后移动

时间:2012-05-12 21:42:21

标签: android sqlite cursor android-cursor

我正在使用光标查找最大ID号,然后我需要转到该记录的5个后面。例如,我在id = 9,我想去id = 5,我该怎么做? 我试过了

int position=cursor.getPosition();  
cursor.moveToPosition(position-5);

但是,它给出了一个错误

 ID  TITLE     FOLDER   PARENT
    1   folder1      1        0
    2   item1        0        1
    3   item2        0        1
    4   folder2      1        1
    5   item1        0        4
    6   item2        0        4
    7   folder3      1        4
    8   item1        0        7
    9   item2        0        7

Cursor cursor = db.rawQuery(“SELECT id,title,folder,parent FROM mydata WHERE”+                      “id =(SELECT MAX(id)FROM mydata);”,null);

1 个答案:

答案 0 :(得分:1)

您可以尝试:

cursor.moveToPosition(cursor.getCount() - 5);

假设光标中至少有5个项目。

<强>更新

您只是请求ID最高的行的详细信息。

要获取原始请求,请尝试以下查询:

SELECT id,title,folder,parent FROM mydata

使用上面的代码建议。

相关问题