0

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

我尝试过改变各种事情,甚至为适配器创建一个单独的类,但适配器类也被证明是有问题的。要么是“this”/上下文,要么与自定义布局有关。我不确定,我一直在寻找答案。

提前致谢。

        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 对其进行了测试。

4

0 回答 0