How to get the row count of a query in Android using SQLite?
cursor.moveToNext();
cursor.getCount();
If the moveToNext() is not called, the cursorIndexOutOfBoundException may arise.
This would be more efficient because work for all versions:
int numRows = DatabaseUtils.longForQuery(db, "SELECT COUNT(*) FROM table_name", null);
or
int numRows = DatabaseUtils.queryNumEntries(db, "table_name");
or if you want to get number of rows which specific selection then you should go with (added in API 11)
public static long queryNumEntries (SQLiteDatabase db, String table, String selection)
Thanks :)
Cursor.getCount()