askIT

Update (Android SQLite)

To update a row in SQLite we need a separate method in DBadapter. This method contains fields to be updated in addition to an ID field (field with the primary key).

Struktur for notes

Field Type Key
note_id int Primary key
note_title varchar
note_text text

Data i notes

note_id note_title note_text
1 Shopping list Cola Zero, Crispbread
2 Music ACDC
3 Homework Law page 119-134
4 Homework Road traffic law page 84-99

DBadapter.class

public boolean updateRecordNote(long inpId, String inpTitle, String inpText) {
                ContentValues args = new ContentValues();
                args.put("note_title", inpTitle);
                args.put("note_text", inpText);
                return db.update(databaseTableNotes, args, "note_id=" + inpId, null) > 0;
}

MainActivity

// Update row
long id = 3;
db.updateRecordNote(id, "Homework in law", "Law page 119-134");

Data in notes after update

note_id note_title note_text
1 Shopping list Cola Zero, Crispbread
2 Music ACDC
3 Homework in law Law page 119-134
4 Homework Road traffic law page 84-99

Add comment

avatar_blank_60.png

Comment:

Name:

Email:

Comments

No comments yet. You can be the first one to comment. Just write your comment in the form and click on the submit button.