jeudi 24 mars 2016

Inserting and deleting information, SQLite database

I'm working with this tutorial http://ift.tt/1e3HL0t and author created methods : addContact and deleteContact. I understood how I can add contact: database.addContact(new Contact("Ravi", "9100000000")); but how can I delete that contact? Somebody please help me!

addContact:

void addContact(Contact contact) {
        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(KEY_NAME, contact.getName()); // Contact Name
        values.put(KEY_PH_NO, contact.getPhoneNumber()); // Contact Phone

        // Inserting Row
        db.insert(TABLE_CONTACTS, null, values);
        db.close(); // Closing database connection
    }

deleteContact:

public void deleteContact(Contact contact) {
        SQLiteDatabase db = this.getWritableDatabase();
        db.delete(TABLE_CONTACTS, KEY_ID + " = ?",
                new String[] { String.valueOf(contact.getID()) });
        db.close();
    }

Aucun commentaire:

Enregistrer un commentaire