0
我正在从android网站的记事本教程工作。我创建了一个包含2个条目的数据库:名称和地址。当应用程序运行时,只显示名称。我想显示姓名和地址。我编辑了我的filldata方法,但它不起作用。看到我的代码如下。有什么建议么?SQLite更改列表的布局
private void fillData() {
Cursor notesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(notesCursor);
// Create an array to specify the fields we want to display in the list (TITLE + BODY)
String[] from = new String[]{NotesDbAdapter.KEY_TITLE,NotesDbAdapter.KEY_BODY};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.text1};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.notes_row, notesCursor, from, to);
setListAdapter(notes);
}
谢谢。我试图在我的notes_row文件中创建第二个textview,并继续收到错误。我的代码如下所示。任何想法?'$ <?xml version =“1.0”encoding =“utf-8”?> –
DMC
@ user876343请参阅我编辑的答案。在xml布局中,你必须只有一个根元素,因此你必须用另一个元素(我使用'LinearLayout',但还有其他选项)包装你的两个'TextView'。用我的上面的代码,你将有一个布局,两个'TextView',一个在另一个之上。 – Luksprog
谢谢,我自己在那里工作!欢呼的帮助! – DMC