我想在android中计算一个表的行.我使用了两种方法,但没有成功&收到警告信息
Launch timeout has expired, giving up wake lock!
Activity idle timeout for HistoryRecord{44e26a30 com.india.screen/.CategoryList}
我试过了-
String query="Select count(*) from Holyplace_Tbl";
>使用rawQuery
public void countRows(String query){
Cursor mcursor = assetDatabaseHelper.executeQuery(query);
mcursor.movetoFirst();
int icount = mcursor.getInt(0);
System.out.println("NUMBER IN DB: " + icount);
mcursor.close();
}
>使用DatabaseUtils
public int countRows(String query)
{
int sometotal = (int) DatabaseUtils.longForQuery(sqliteDatabaSEObj, query, null);
return sometotal;
}
解决方法:
试试这个
private static final String DB_TABLE_PLACES = "Places";
private sqliteDatabase mDatabase;
private long fetchPlacesCount() {
String sql = "SELECT COUNT(*) FROM " + DB_TABLE_PLACES;
sqliteStatement statement = mDatabase.compileStatement(sql);
long count = statement.simpleQueryForLong();
return count;
}
查看更多Here.