0
// 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 );
}

--- 项目dbadapter.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
4

1 回答 1

0

尝试将您的 sql 编辑为此:

String count = "SELECT COUNT("+KEY_ROWID_REL+ ") AS MYCOUNT FROM "+  DATABASE_TABLE_REL;
于 2013-01-25T10:46:16.993 回答