// Getting contacts Count
public int getAllReleasesCount() {
SQLiteDatabase mDb = mDbHelper.getWritableDatabase();
String count = "SELECT COUNT"+(KEY_ROWID_REL)+ " FROM "+ DATABASE_TABLE_REL;
Cursor mcursor = mDb.rawQuery(count, null);
mcursor.moveToFirst();
int icount = mcursor.getInt(0);
System.out.println("NUMBER IN DB: " + icount);
// return count
return icount();
}
public long fetchAllReleasesCount(){
return DatabaseUtils.queryNumEntries(mDb, DATABASE_TABLE_REL );
}
--- projectdbadapter.java
private void fillData() {
mDbHelper.open();
Cursor projectsCursor = mDbHelper.fetchAllProjects();
startManagingCursor(projectsCursor);
// Create an array to specify the fields we want to display in the list (only TITLE)
String[] from = new String[]{ProjectsDbAdapter.KEY_TITLE};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.text1};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter projects =
new SimpleCursorAdapter(this, R.layout.activity_row, projectsCursor, from, to);
setListAdapter(projects);
}---- project list activity
答案 0 :(得分:0)
尝试编辑你的SQL:
String count = "SELECT COUNT("+KEY_ROWID_REL+ ") AS MYCOUNT FROM "+ DATABASE_TABLE_REL;