Friday, March 6, 2015

Iterate a SQLite Cursor Object in Android

There are numerous ways of iterating over a cursor object. This is what I prefer:

cursor.moveToFirst();
while (!cursor.isAfterLast()) {
  // Do something
  cursor.moveToNext();
}
cursor.close();


Here's another one (this is one of the simplest approach):
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()){
  // Do something
}

No comments:

Post a Comment