如何在列表视图中获取sqlite计数?

时间:2013-01-25 07:08:57

标签: android sqlite android-listview count

这是计算任务的正确代码吗?如何在列表视图中获取这些计数?//获取联系人计数

public int getTaskCount() {
     String countQuery = "SELECT Count(KEY_ROWID_REL) FROM  " + DATABASE_TABLE_REL;
     SQLiteDatabase db = this.getReadableDatabase();
     Cursor mcursor = db.rawQuery(countQuery, null);
     mcursor.moveToFirst();

     // return count
     return mcursor.getCount();
 }    

 private SQLiteDatabase getReadableDatabase() {
 // TODO Auto-generated method stub
 return null;
}

public long fetchAllProjectscount(int rowId) {
   String countQuery = "SELECT Count KEY_ROWID_REL FROM  " + DATABASE_TABLE_REL;
   SQLiteStatement statement =mDb.compileStatement(countQuery);
   return (int) statement.simpleQueryForLong();     
}

1 个答案:

答案 0 :(得分:1)

你的查询错了,这是正确的:

SELECT Count(KEY_ROWID_REL) FROM DATABASE_TABLE_REL;