I'm trying to develop a simple Sqlite application to understand Crud operations. I have book class user should be able to select instert update and delete.When user wants to delete a data, user is asked that he is want to delete book data.There is two buttons on alertdialog box Yes or No. If user click on setPositiveButton deletion operation is materialized. But i can't get context in Code onClick Method.Code is as following
AlertDialog.Builder alertDialog = new AlertDialog.Builder(KitapDetay.this);
alertDialog.setTitle("Alert");
alertDialog.setMessage("Do you want to delete book ?");
alertDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
BookRepo repo = new BookRepo(this);
repo.deleteBook(id);
Toast.makeText(getApplicationContext(), "Book is deleted successfully", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
}
});