首先在CrimeLab.java中添加删除的方法
public void deleteCrime(Crime crime){
String uuidString = crime.getId().toString();
mDatabase.delete(CrimeDbSchema.CrimeTable.NAME,
CrimeDbSchema.CrimeTable.Cols.UUID + "= ?" ,
new String[] {uuidString}
);
}
在CrimeListFragment.java中获取crime并进行删除操作
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_item_delete_crime:
CrimeLab.get(getActivity()).deleteCrime(mCrime);
getActivity().finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}