Solution 1 :
This does the trick:
cursor.moveToFirst();
cursor.move(-1);
Problem :
I have a Cursor returned by dbHelper.getReadableDatabase().query().
I can loop through the cursor using:
while(cursor.moveToNext()) {}
Then I would like to reset the cursor and loop again.
I tried:
cursor.moveToFirst() // this return true
while(cursor.moveToNext()) {}
But this never goes into the while loop.
How can I loop cursor twice?
EDIT: OK, I get it. moveToFirst does exactly what its name suggests – it moves cursor to point to the first item. Then, if my cursor holds just 1 item, moveToNext returns false always. So the question is: how to reset cursor?
Comments
Comment posted by blackapps
if (cursor.moveToFirst()) do { } while(cursor.moveToNext())
Comment posted by blackapps
You should code it like that for the first loop too.