I am working on android project. I used sqlite database for it. I have tables in database. I have created databasehelper class. i want to count number of records in particul
Please try this:
In your DatabaseHelper.java:
public Cursor getYourTableContents() {
SQLiteDatabase db = this.getWritableDatabase();
Cursor data = db.rawQuery("SELECT * FROM " + "Your table name", null);
return data;
}
To get the number of rows in your table:
Cursor yourCursor = myDB.getYourTableContents();
int i = 0;
while (yourCursor.moveToNext()) {
i += 1;
}
i
is your rows count as an integer.