开发者

Inserting the multiple values in the database on OnClickListener event

开发者 https://www.devze.com 2023-04-13 09:24 出处:网络
I want to insert multiple values in the database when in click the save button but the code not work correctly ?

I want to insert multiple values in the database when in click the save button but the code not work correctly ?

public void insert(String note) {
        ContentValues cv = new ContentValues();
        ContentValues cv1 = new ContentValues();
        ContentValues cv2 = n开发者_StackOverflow社区ew ContentValues();
        cv.put("note", note);
        cv1.put("topic",topic1);
        cv2.put("subTopic",subTopic1);
        getWritableDatabase().insert("Notes", "note", cv);
        getWritableDatabase().insert("Notes", "topic", cv1);
        getWritableDatabase().insert("Notes", "subTopic", cv2); }




private View.OnClickListener onSave = new View.OnClickListener() {

    public void onClick(View v) {
        if (noteId == null) {
            helper.insert(editNote.getText().toString(), , );
        } else {
            helper.update(noteId, editNote.getText().toString());
            noteId = null;
        }
        ourCursor.requery();
        editNote.setText("");
    }
};


Try this code for inserting mutiple columns :

public void insert(String note,String topic,String subTopic) {
     ContentValues initialValues = new ContentValues();
     initialValues.put("note", category);
     initialValues.put("topic", notes_date);
     initialValues.put("subTopic", notes_date);
     mDb.insert(DATABASE_TABLE, null, initialValues);
}

Where mdb is instance SQLiteDatabase mDb= mDbHelper.getWritableDatabase();

DATABASE_TABLE - table name.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号