Cursor cursor = db.rawQuery("SELECT * FROM myTable;", null); if (!cursor.moveToFirst()) { // Handle empty result set } do { // Do something with the current row of data if (cursor.isAfterLast()) { // Finished processing result set break; } } while (cursor.moveToNext());
Cursor cursor = db.rawQuery("SELECT * FROM myTable;", null); if (!cursor.moveToFirst()) { // Handle empty result set } while (cursor.moveToNext() && !cursor.isAfterLast()) { // Skip some rows we don't care about } do { // Do something with the current row of data } while (cursor.moveToNext());This example shows how to skip over rows in a cursor until the end of the result set using isAfterLast(). It first calls moveToFirst() to position the cursor on the first row of data, and then uses a while loop to skip over rows that aren't relevant to the app's needs. Once it reaches the end of the irrelevant rows, it uses a do-while loop to process each row of data returned by the query. The android.database.Cursor interface is part of the Android SDK, so it's available in the android.database package library.