SimpleCursorAdapter崩溃

时间:2013-05-04 22:22:34

标签: android android-layout

Android在遇到“SimpleCursorAdapter NotesAdapter = new SimpleCursorAdapter(this,R.layout.manage_notes_noteitem_layout,)

这一行时继续崩溃

我尝试过改变各种各样的东西,甚至为Adapter创建一个单独的类,但Adapter类也证明是有问题的。要么它是“this”/ context,要么与自定义布局有关。我不确定,我一直在寻找答案。

提前致谢。

        String[] columns = new String[] {
        NotesAdapter.KEY_NoteTitle,
        NotesAdapter.KEY_Created,
        NotesAdapter.KEY_NoteText,
      };

      // the XML defined views which the data will be bound to
      int[] to = new int[] { 
        R.id.note_title,
        R.id.note_datedcreated,
        R.id.note_details,
      };

      // create the adapter using the cursor pointing to the desired data 
      //as well as the layout information
      SimpleCursorAdapter NotesAdapter = new SimpleCursorAdapter(
        this, R.layout.manage_notes_noteitem_layout, 
        C, 
        columns, 
        to,
        0);

NotesAdapter类的更新:

public class NotesAdapter extends DBAdapter 
{

public static final String KEY_NoteID = "NoteID";
public static final String KEY_NoteTitle = "NoteTitle";
public static final String KEY_NoteText = "NoteText";
public static final String KEY_Created = "Created";
private static final String DATABASE_TABLE = "notes";

public NotesAdapter(Context ctx) {
    super(ctx);
}

public long create(String NoteID, String NoteTitle, String NoteText, String Created) {
    ContentValues args = new ContentValues();
    args.put(KEY_NoteID,NoteID);
    args.put(KEY_NoteTitle,NoteTitle);
    args.put(KEY_NoteText,NoteText);
    args.put(KEY_Created,Created);

    return mDb.insert(DATABASE_TABLE, null,args);
}

public boolean delete(String RowID) {
    return mDb.delete(DATABASE_TABLE, KEY_NoteID + "=" + RowID, null) > 0;
}

public Cursor fetchAll() {
    return mDb.query(DATABASE_TABLE, new String[] {KEY_NoteID, KEY_NoteTitle, KEY_NoteText, KEY_Created}, null, null, null, null, null);
}

public Cursor fetch(long rowId) throws SQLException {
    Cursor mCursor =
        mDb.query(true, DATABASE_TABLE, new String[] {KEY_NoteID, KEY_NoteTitle, KEY_NoteText, KEY_Created}, KEY_NoteID + "=" + rowId, null,
                null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;
}

}

编辑:光标确实返回有效值,因为我使用Toasts进行了测试。

0 个答案:

没有答案