mercredi 28 octobre 2015

Delete specific row by ID in SQLite

Before marking this question as duplicate please read through! I've done a lot of research but I couldn't find my answer. All I want to know is how I can use my delete method in my activity!

My method in my DB class:

public void deleteRecord(DataBean dataBean) {

    SQLiteDatabase db = helper.getWritableDatabase();

    db.delete(LysandrosHelper.TABLE_NAME, LysandrosHelper.UID + " ?", new String[] { String.valueOf(dataBean.getID())});
    db.close();
}

DataBean is my adapter class that handles the information.

This is where I'm using my method but I can't find what I'm missing between the brackets on the lysandros.deleteRecord() line! This is an Activity that displays information for a selected employee, like in a card.

public void DeleteRecord() {

    lysandrosHelper = new LysandrosDatabaseAdapter(this);

    deleteRecord = (ImageButton) findViewById(R.id.delete_button);
    deleteRecord.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            lysandrosHelper.deleteRecord();

            startActivity(new Intent(v.getContext(), EmployeeDirectory.class));
        }
    });
}

Please any guidance or help is much appreciated!!

Aucun commentaire:

Enregistrer un commentaire