jeudi 1 janvier 2015

How to update a record in SQLite with Android?

How to update a record in SQLite with Android?


Hello.


I write because I am unfortunately stuck in my project and I hope you can help me. How do I update a record in a database?


For example in a contact database. In this database of contacts, the following keys are used: name, phone, email and address; my problem is when I need to modify a record, what must I do to modify a record.


I hope you can help me. Thanks in advance.


This is the SQLite code to update the registry:



// Updating single contact


public int updateContact(Contact contact) {


SQLiteDatabase db = this.getWritableDatabase();



ContentValues values = new ContentValues();
values.put(KEY_NAME, contact.getName());
values.put(KEY_PH_NO, contact.getPhoneNumber());

// updating row
return db.update(TABLE_CONTACTS, values, KEY_ID + " = ?", new String[] { String.valueOf(contact.getID()) });


}


This same code I have found on many websites, but my problem is how to call the code from the MainActivity with Java.


Aucun commentaire:

Enregistrer un commentaire