您好我是Android的新手并从SQlite表获取总行数并将其设置为文本视图。我已经搜索了很多相关的帖子,但遗憾的是无法成功,任何人帮助我plzzz ...
这是我的查询
Cursor cur = mDb.rawQuery(" SELECT Count(*) FROM Tasks ", null);
int x = cur.getCount();
cur.close();
return x;
我的java代码是
TextView count = (TextView) findViewById(R.id.txtcount);
count.setText(String.valueOf(myAdapter.GetTasksCount()));
提前致谢
答案 0 :(得分:1)
SQL方法(尚未检查) -
Cursor cur = mDb.rawQuery(" SELECT Count(*) FROM Tasks ", null);
int x = 0;
if (cur.moveToFirst())
{
x = cur.getInt(0);
}
cur.close();
return x;
答案 1 :(得分:0)
试试这个:
myAdapter.openToRead();
int i = myAdapter.GetTasksCount();
TextView count = (TextView) findViewById(R.id.txtcount);
count.setText(Integer.toString(i));