使用SimpleCusorAdapter填充android的ListView

使用SimpleCusorAdapter填充android的ListView,android,sqlite,listview,cursor,cursors,Android,Sqlite,Listview,Cursor,Cursors,我试图从SQLite数据库中获取多个数据片段到ListView中,但它似乎不起作用 我使用的是developer.android.com记事本示例中的代码,它适用于1条数据,但不适用于2条 我试图从数据库中获取每个数据库条目的标题和主体,通过光标进入视图,我认为我的问题在于xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/

我试图从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>
如果我只使用一个文本视图(如记事本教程中的文本视图)将KEY_TITLE转换为.xml,那么这很好,但是如果我尝试使用上面定义的xml运行它,它将强制关闭

你知道为什么吗

谢谢你抽出时间


InfinitiFizz

如果您创建自定义适配器而不是使用“SimpleCorsorAdapter”会更好

基本上,您需要做的是创建一个从“CursorAdapter”派生的新类,然后实现“newView”和“bindView”方法。
在这两种方法中,您都可以将光标指向正确的位置,以便直接访问内容并在视图和数据之间映射。

使用Eclipse中的
adb logcat
、DDMS或DDMS透视图来获取与异常相关的堆栈跟踪,所以你可以看到哪里出了问题。对不起,我以前没有为android做过任何调试,有什么好的指南/教程让我开始学习这些东西吗?
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);