2014-10-01 14 views
0

我從如下谷歌http://developer.android.com/training/notepad/notepad-ex1.html如何在兩個TextView顯示兩個DB鍵

我已經改變了listiew到GridView註釋教程,我要顯示的標題在textview1和片段的所有創建的註釋在textview2中的body。

在本教程中,我們希望獲得KEY_TITLE並將其輸入到textview1中,但我怎麼能爲KEY_TITLE和KEY_BODY這樣做?

private void fillData() { 
    Cursor notesCursor = mDbHelper.fetchAllNotes(); 
    startManagingCursor(notesCursor); 

    String[] from = new String[]{NotesDbAdapter.KEY_TITLE}; 

    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, flags); 
    setListAdapter(notes); 
} 

一個天真的做法是有from2爲KEY_BODY和TO2爲text2的第2個CursorAdapter的,但是這使得文本1爲空 - >失敗!

回答

1

用另一個ID添加第二個TexTView到你的行佈局(我們稱之爲test2)。然後,只需更改fromto陣列:

String[] from = new String[]{NotesDbAdapter.KEY_TITLE, NotesDbAdapter.KEY_BODY}; 
int[] to = new int[]{R.id.text1, R.id.text2}; 
+0

啊,太簡單了!我用'+'而不是''試過,愚蠢的我。非常感謝您的快速重播! – sascha 2014-10-01 15:43:39