UzUmAkI_NaRuTo
UzUmAkI_NaRuTo

Reputation: 575

Moving android sql lite cursor forward

I have a Sql lite table in my application.

I want to add a cursor to parse the table such that it moves ahead from the current position.
Main idea is to update all next rows and not previous one.

can anyone give me a example cursor to do so with any loops if required ?

Upvotes: 0

Views: 336

Answers (1)

PPartisan
PPartisan

Reputation: 8231

if (cursor.moveToFirst()) { //Replace this with cursor.moveToPosition(position) to iterate from that position to the end of your cursor, rather than from start to finish.
    while (!cursor.isAfterLast()){
          cursor.getInt(0); //get whatever information you require.
          cursor.moveToNext();
    }
    if (!cursor.isClosed()) {
        cursor.close();
    }
}

There are many ways to achieve this. In the above example, I first check to ensure that the cursor isn't empty, and then go through each row one by one until I reach the final row. When done, I call close() on the cursor.

Upvotes: 2

Related Questions