0

嗨,我是 android 新手,从 SQlite 表中获取总行数并将其设置为 textview 的文本。我已经搜索了很多阅读许多相关的帖子,但不幸的是无法成功任何人帮助我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())); 

提前致谢

4

2 回答 2

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;
于 2013-02-16T11:34:51.263 回答
0

试试这个:

    myAdapter.openToRead();
    int i = myAdapter.GetTasksCount();
    TextView count = (TextView) findViewById(R.id.txtcount);
   count.setText(Integer.toString(i)); 
于 2013-02-16T11:04:49.713 回答