公式NotePadインスタンス学習--データContentValueの保存

931 ワード

ContentValueクラスは、ContentResolverの処理を容易にするために値のセットを保存します.一般的には、データベースがデータを挿入および更新するときに使用されます.
public long createNote(String title, String body) {
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_TITLE, title);
        initialValues.put(KEY_BODY, body);
        return mDb.insert(DATABASE_TABLE, null, initialValues);
    }

 
public boolean updateNote(long rowId, String title, String body) {
        ContentValues args = new ContentValues();
        args.put(KEY_TITLE, title);
        args.put(KEY_BODY, body);
        return mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;
    }

ContentValueクラスは実はHashMapをカプセル化する方法です.ContentValueは様々なデータ型のputとgetメソッドを提供しており、私たち自身がタイプ変換を行う必要はありません.HashMapは同期の問題に注意し、マルチスレッドを使用するときに注意する必要があります.