setListAdapter有多个项目?

时间:2014-10-28 04:23:48

标签: android sqlite

是否可以SimpleCursorAdapter检索多个项目并显示它们?这是来自Android记事本教程(编辑了一下),当我尝试拉它AScoresDbAdapter.KEY_COL2_NAME, AScoresDbAdapter.KEY_COL1_DATE时,它只显示TextView

中的第一个

有这个原因还是我错过了什么?

private void fillData() {
    // Get all of the notes from the database and create the item list
    Cursor c = scoresDbAdapter.fetchAllNotes();
    startManagingCursor(c);

    String[] from = new String[] { AScoresDbAdapter.KEY_COL2_NAME, AScoresDbAdapter.KEY_COL1_DATE};
    int[] to = new int[] { R.id.text1 };

    // Now create an array adapter and set it to display using our row
    SimpleCursorAdapter notes =
            new SimpleCursorAdapter(this, R.layout.shots_row, c, from, to,0);
    setListAdapter(notes);

}

1 个答案:

答案 0 :(得分:0)

好吧所以我想它一开始就告诉我他们是数组而且它可能只放了一个from一个int所以我添加了另一个TextView并编辑了上面的内容这样:

String[] from = new String[] { AScoresDbAdapter.KEY_COL1_DATE,AScoresDbAdapter.KEY_COL2_NAME};
    int[] to = new int[] { R.id.text1, R.id.text2 };

现在显示[Date][Name]而非[Date][Name]

不确定这是否正确,但如果有更好的方法,我会很高兴知道它。