Cursor moveToFirst - Move Cursor to the First Row
- Cursor.moveToFirst () was added in API Level 1
Move the cursor to the first row. This method will return false if the cursor is empty. Returns whether the move succeeded.
1. Define a Cursor named myCursor.
2. Load the Cursor using managedQuery(for API Level's < 11), otherwise use ContentLoader.
3. In the MainActivity. java file, on the onCreate method, add the following code.
- if (myCursor != null) { //Tests to see if the cursor exists.
if (myCursor.moveToFirst()) {
- // myCursor moved to the first record
} else {
// myCursor is empty
}
- } else {
// myCursor is null
- }
4. Compile and run!
Resources:
http://developer.android.com/reference/android/database/Cursor.html#moveToFirst()