Delete from Database

I want to delete the crime from my DB, i tried to use ‘valuse’ to do this but it’s not working;
how can i get id of the row that user click in the list? to pass it in my Delete method…
Thanks in advance))

here is my delete method inside the CrimeLab:

public void deleteCrime (Crime crime) {
String uuidString = crime.getId().toString();
ContentValues values = getContentValues(crime);
mDatabase.delete(CrimeTable.NAME,
uuidString + " = ?" ,
new String[] { uuidString });
}

Hey, here, I found a solution

my onOptionsItemSelected from CrimeFragment is

public boolean onOptionsItemSelected(MenuItem item) {
        switch(item.getItemId()){
            case R.id.delete_crime:
                CrimeLab.get(getActivity()).deleteCrime(mCrime);
           getActivity().finish();
                return true;
            default:
                return super.onOptionsItemSelected(item);

Secondly, my CrimeLab is

public void deleteCrime(CrimeDec crime) {
        mDatabase.delete(CrimeTable.TABLE_NAME, CrimeTable.Cols.UUID + " = ?", new String[]{crime.getId().toString()});
    }

it’s work for me!

5 Likes

Hey,
yes it worked for me too!
thanks!
the way u wrote in ‘mDatabase.delete’ is so clear && simple…
I should have try that instead of define a new method for getting id and so on