我的大部分 Android 问题都已从该站点得到解答,但我有一个特殊问题我无法找到。我想使用 textview 从 SQLite 数据库中检索记录的各个列。例如,
欢迎 COLUMN1VALUE,根据我们的记录,您住在 COLUMN2VALUE 并且已经在那里生活了 COLUMN3VALUE 年。
任何人都可以指出我的教程方向或给我一个答案吗?谢谢!
这是代码:
private void fillData(Uri uri) {
String[] projection = { TodoTable.COLUMN_COREBELIEF,
TodoTable.COLUMN_EXPERIENCE1,
TodoTable.COLUMN_EXPERIENCE2,
TodoTable.COLUMN_EXPERIENCE3,
TodoTable.COLUMN_NEWBELIEF,};
// String query = "SELECT COLUMN_NEWBELIEF,COLUMN_COREBELIEF,COLUMN_EXPERIENCE1 FROM TodoTable";
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
// Cursor cursor = db.rawQuery(query, null);
if (cursor != null) {
cursor.moveToFirst();
String s = String.format("Welcome %s, from our records you are living in %s and have been living there for %s years.", cursor.getString(cursor.getColumnIndex("COLUMN_NEWBELIEF")), cursor.getString(cursor.getColumnIndex("COLUMN_COREBELIEF")), cursor.getString(cursor.getColumnIndex("COLUMN_EXPERIENCE1")));
textView1.setText(s);
}
// mCoreBelief.setText(cursor.getString(cursor
// .getColumnIndexOrThrow(TodoTable.COLUMN_COREBELIEF)));
// mExperience1.setText(cursor.getString(cursor
// .getColumnIndexOrThrow(TodoTable.COLUMN_EXPERIENCE1)));
// mExperience2.setText(cursor.getString(cursor
// .getColumnIndexOrThrow(TodoTable.COLUMN_EXPERIENCE2)));
// mExperience3.setText(cursor.getString(cursor
// .getColumnIndexOrThrow(TodoTable.COLUMN_EXPERIENCE3)));
// mNewBelief.setText(cursor.getString(cursor
// .getColumnIndexOrThrow(TodoTable.COLUMN_NEWBELIEF)));
// Always close the cursor
cursor.close();
}