Android ListView在我更改其表后不工作。安卓
我创建了一个列表视图,在屏幕上显示数据库的所有内容。我使用的代码是Android ListView在我更改其表后不工作。安卓,android,sqlite,android-listview,Android,Sqlite,Android Listview,我创建了一个列表视图,在屏幕上显示数据库的所有内容。我使用的代码是 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_DA
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我唯一能想到的是您的新
光标
没有名为\u id
的列。确保光标
Cursor c = datasource.getAllActs();
有一个名为
\u id
的列,这是SimpleCursorAdapter
类所要求的。我唯一能想到的是,新的光标
没有一个名为\u id
的列。确保光标
Cursor c = datasource.getAllActs();
有一个名为
\u id
的列,这是SimpleCorsOrAdapter
类所需要的。忘记日志。。。从你的帖子中,我甚至不知道问题出在哪里。请发布logcat错误,这样如果Alex没有猜到的话,我们就可以看到问题出在哪里。忘记logcat。。。从你的帖子中,我甚至无法判断问题是什么。请发布logcat错误,这样如果Alex没有猜到,我们就可以看到问题是什么。可能是这样的,因为_ID不是gatAllActs()表的一部分;正在访问。另外,Alex是否有多个表具有相同的_id字段会导致任何问题。事实上,通常认为最好的做法是让所有表都包含一个自动递增的主键(即\u id
)。每个表的列完全独立于任何其他表的列。除非您正在执行某种复杂的连接
,否则应该不会有任何问题。我有点认为,在创建主键时,字段名需要是唯一的。因此,我可以有3个表,每个表都有相同的主键,名称为“\u id”。假设您有两个表,table1
和table2
,这两个表都有一个名为\u id
的列。然后在SQLite语法中,您可以使用table1.\u id
和table2.\u id
引用这些列,因此您可以看到它们都是唯一的。唯一的限制是一个表不能包含两个名称相同的列(显然),这可能是因为_ID不是gatAllActs()表的一部分;正在访问。另外,Alex是否有多个表具有相同的_id字段会导致任何问题。事实上,通常认为最好的做法是让所有表都包含一个自动递增的主键(即\u id
)。每个表的列完全独立于任何其他表的列。除非您正在执行某种复杂的连接
,否则应该不会有任何问题。我有点认为,在创建主键时,字段名需要是唯一的。因此,我可以有3个表,每个表都有相同的主键,名称为“\u id”。假设您有两个表,table1
和table2
,这两个表都有一个名为\u id
的列。然后在SQLite语法中,您可以使用table1.\u id
和table2.\u id
引用这些列,因此您可以看到它们都是唯一的。唯一的限制是一个表不能包含两个名称相同的列(显然)。