Reputation: 2221
I am using cursor to find out max id number then I need to go to 5 backwards of that record. For example, I am in id=9 and I want to go to id=5,How can I do it ? I tried
int position=cursor.getPosition();
cursor.moveToPosition(position-5);
But, It gives an error
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);
Upvotes: 0
Views: 297
Reputation: 86948
You can try:
cursor.moveToPosition(cursor.getCount() - 5);
This assumes you have at least 5 items in the cursor.
Update
You are only requesting the details on the row with the highest id.
To get your original request try this query:
SELECT id,title,folder,parent FROM mydata
With the code suggestion above.
Upvotes: 1