public List<UserDataHelper> getData() {
List<UserDataHelper> list = new ArrayList<UserDataHelper>();
String selectQuery = "SELECT * FROM " + TABLE;
dbase = this.getReadableDatabase();
Cursor cursor = dbase.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
UserDataHelper quest = new UserDataHelper();
quest.setID(cursor.getInt(0));
quest.setName(cursor.getString(1));
quest.setSent(cursor.getInt(2));
quest.setRecieved(cursor.getInt(3));
quest.setTotal(cursor.getInt(4));
quest.setTimeSpent(cursor.getString(5));
list.add(quest);
} while (cursor.moveToNext());
}
return list;
}
这是用于listView的,但是我想单独获取数据并将其显示在textView中。我该如何实现?有很多关于列表视图的教程,但没有关于文本视图的教程,所以有人可以帮我吗。
答案 0 :(得分:0)
尝试
for (UserDataHelper user:getData())
{
textView.append(user.getID()+" "+user.getName()
+" "+user.getRecieved()+" "+user.getSent()
+" "+user.getTimeSpent()+" "+user.getTotal()+"\n");
}
答案 1 :(得分:0)
您可以简单地使用class对象来设置/获取值,对字符串值执行以下操作:-
textView.setText(quest.getName());
,对于整数值,请确保使用一个
以下内容之一:-
textView.setText(""+quest.getId());
或
textView.setText(String.valueOf(integer));