我正在尝试将 SQLite 数据库中的多条数据获取到 ListView 中,但它似乎不起作用。
我正在使用 developer.android.com 的记事本示例中的代码,它适用于 1 条数据,但不适用于 2 条数据。
我正在尝试通过游标从数据库中获取每个数据库条目的标题和正文并进入视图,我认为我的问题出在 xml 上:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
<TextView android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
</LinearLayout>
这是我尝试绑定值的代码:
mNotesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(mNotesCursor);
String[] from = new String[]{NotesDbAdapter.KEY_TITLE, NotesDbAdapter.KEY_BODY};
int[] to = new int[]{R.id.text1, R.id.text2};
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.notes_row, mNotesCursor, from, to);
setListAdapter(notes);
如果我只是将 KEY_TITLE 放入只有一个 TextView 的 .xml 中(就像在记事本教程中一样),那很好,但如果我尝试使用上面定义的 xml 运行它,它会强制关闭。
任何想法为什么?
谢谢你的时间,
英菲尼迪菲兹