我创建了一个列表视图,以在屏幕上显示数据库的所有内容。我正在使用的代码就是这个
private void fillData() {
// Get all of the notes from the database and create the item list
Cursor c = datasource.getAllActs();
startManagingCursor(c);
String[] from = new String[] {DataBaseHelper.KEY_DATE,
DataBaseHelper.KEY_STEPS,DataBaseHelper.KEY_CALs };
int[] to = { R.id.code, R.id.Days, R.id.BMI };
SimpleCursorAdapter notes = new SimpleCursorAdapter (this, R.layout.notes_row, c, from, to);
setListAdapter(notes);
}
与下面的代码一起工作。
private void fillData() {
// Get all of the notes from the database and create the item list
Cursor c = datasource.getAllGoals();
startManagingCursor(c);
String[] from = new String[] {DataBaseHelper.KEY_GOAL, DataBaseHelper.KEY_Current,DataBaseHelper.KEY_Target };
int[] to = { R.id.code, R.id.Days, R.id.BMI };
SimpleCursorAdapter notes = new SimpleCursorAdapter (this, R.layout.notes_row, c, from, to);
setListAdapter(notes);
}
我只是想知道这段代码是否有问题我可能会遗漏。如果你需要它我有logcat
答案 0 :(得分:1)
我唯一能想到的是,您的新Cursor
没有名为_id
的列。确保光标
Cursor c = datasource.getAllActs();
有一个名为_id
的列,因为SimpleCursorAdapter
类需要它。