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