0

我有一个带有实现的自定义类:

private static class Item {
    String userID;
    String userEmail;

    Item(String userID, String userEmail) {
        this.userID = userID;
        this.userEmail = userEmail;
    }
}

以下是我在 ContentProvider 中更新值的方法:

@Override
public int update(@NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    int itemPosition = 0;

    // Adding dummy data incase Items List is empty.
    if (items.isEmpty()) {
        add(values);
    } else {
        items.set(itemPosition, new Item(values.getAsString(K.USER_ID_COLUMN_NAME), values.getAsString(K.USER_EMAIL_COLUMN_NAME)));
    }
    return notifyChange(uri, itemPosition);
}

以下是我将值传递给方法的方式:

ContentValues values = new ContentValues();
values.put(K.USER_ID_COLUMN_NAME, "1234");
values.put(K.USER_EMAIL_COLUMN_NAME, "test@m.com);

getContext().getContentResolver().update(K.CONTENT_URI, values, null, null);

我的问题是,如何重构更新方法,以便我可以只使用selectionselectionArgs更新其中一列,而其他列保持原样?我不想使用 SQLite 使事情复杂化,但我宁愿使用 MatrixCursor。

4

0 回答 0