Is the documentation for Android Cursor.moveToNext () set correctly?

boolean android.database.Cursor.moveToNext () documentation says:

http://developer.android.com/reference/android/database/Cursor.html#moveToNext%28%29

Move the cursor to the next line.

This method will return false if the cursor has already passed the last record in the result set.


However, my book says to do the following to extract data from the cursor:

Cursor myCursor = myDatabase.query (...);
if (myCursor.moveToFirst ()) {
    do {
    int value = myCursor.getInt (VALUE_COL);
    // use value
    } while (myCursor.moveToNext ());
}

? . , , myCursor 1 , . getInt() , moveToNext() true, "" . , , getInt() - undefined.

, :

false, .

PAST ( AT) , moveToNext() false?

Snark ,

+5
5

Verbatim API:

:      .


, , :

→ moveToNext() → → → return false


, : http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.3.3_r1/android/database/AbstractCursor.java#AbstractCursor.moveToNext%28%29

public final boolean moveToNext() {
  return moveToPosition(mPos + 1);
}

public final boolean moveToPosition(int position) {
    // Make sure position isn't past the end of the cursor
    final int count = getCount();
    if (position >= count) {
        mPos = count;
        return false;
    }
+6

:

Cursor cursor = db.query(...);
while (cursor.moveToNext()) {
    // use cursor
}

, -1, . Cursor.getPosition() docs.

Android Google Code Search. SQLite .

: .

+20

, , : , sqlite api .

, while for. , , , , , while:

for( boolean haveRow = c.moveToFirst(); haveRow; haveRow = c.moveToNext() ) {
...
}

, , 6 , , , .

+2

, AbstractCursor Android, Jellybean.

unit test, , MatrixCursor:

@Test
public void testCursor() {
  MatrixCursor cursor = new MatrixCursor(new String[] { "id" });
  for (String s : new String[] { "1", "2", "3" }) {
    cursor.addRow(new String[] { s });
  }

  cursor.moveToPosition(0);
  assertThat(cursor.moveToPrevious(), is(true));

  cursor.moveToPosition(cursor.getCount()-1);
  assertThat(cursor.moveToNext(), is(true));

  assertThat(cursor.moveToPosition(c.getCount()), is(true));
  assertThat(cursor.moveToPosition(-1), is(true));
}

, moveToNext, moveToPrevious moveToPosition.

API 16 AbstractCursor.moveToPosition(int position), -, , false , .

, Android, , , , Android, . . / javadoc, . , Cursors/CursorWrappers Android, .

+2

Cursor.moveToNext(), , , . , .

https://issuetracker.google.com/issues/69259484

He recommends the following sentence:
"This method will return false if the current (at run time) record is the last record in the set and there will be no next record."

0
source

All Articles