Is Android Cursor.moveToNext() Documentation Correct?

后端 未结 5 1952
春和景丽
春和景丽 2021-01-12 03:00

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

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

Move th

5条回答
  •  旧时难觅i
    2021-01-12 03:20

    I think I tend to stay away from solutions that are based on a hidden assumption like: I hope that sqlite never changes it api and that a cursor will always start at the first item.

    Also, I have almost always been able to replace a while statement with a for statement. So my solution, shows what I expect the cursor to start at, and avoids using a while statement:

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

    why is showing that a cursor needs to start at the first row, well 6 months down the line you might be debugging your own code, and will wonder why you didn't make that explicit so you could easily debug it.

提交回复
热议问题