我如何用标题调用计数值?

时间:2013-01-25 10:34:38

标签: android

// 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

1 个答案:

答案 0 :(得分:0)

尝试编辑你的SQL:

String count = "SELECT COUNT("+KEY_ROWID_REL+ ") AS MYCOUNT FROM "+  DATABASE_TABLE_REL;