Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do Android Cursors start before the first row of results, and end after the last row?

I'm trying to understand why they would start the cursor before the first position in a row and why it would end after the last position. Is there an inherit advantage to doing it this way?

For example:

public abstract int getPosition () 

Since: API Level 1 Returns the current position of the cursor in the row set. The value is zero-based. When the row set is first returned the cursor will be at position -1, which is before the first row. After the last row is returned another call to next() will leave the cursor past the last entry, at a position of count().

returns the current cursor position.

Thank you.

like image 972
evt Avatar asked Jul 13 '12 22:07

evt


1 Answers

Because a Cursor isn't guaranteed to be populated with rows. If you got a Cursor back from a database with 0 rows, the initial position being at 0 doesn't make sense since there isn't a row at position 0.

like image 168
Jason Robinson Avatar answered Sep 19 '22 12:09

Jason Robinson