1

I have created an Alert Popup that asks the user whether they want to edit or delete a reminder.

If the user clicks on the delete reminder button I want to show another Alert Popup that asks whether the user is sure or not.

Something like this:

AlertDialog.Builder dialog = new AlertDialog.Builder(this);
            AlertDialog alert = dialog.Create();
            alert.SetTitle("Edit or Delete?");
            alert.SetMessage("Would you like to edit your reminder or delete it?");
            alert.SetIcon(Resource.Drawable.image_2020_09_29T09_45_02_165Z);
            alert.SetButton("Delete", (c, ev) =>
            {
                alert.SetTitle("Delete Reminder");
                alert.SetMessage("Are you sure!");
                alert.SetIcon(Resource.Drawable.Screenshot_2020_11_10_at_8_05_44_AM);
                alert.SetButton("yes", (c, ev) =>  
                {
                    TextView _txtLabel;
                    reminder = listitem[e.Position];  
                    ReminderHelper.DeleteReminder(this,reminder);
                    _txtLabel = FindViewById<TextView>(Resource.Id.txt_label);
                    StartActivity(new Intent(this, typeof(ListReminder)));
                    Toast.MakeText(this, "Deleted Sucessfully!", ToastLength.Short).Show();
                    GC.Collect();  
                });
                alert.SetButton2("no", (c, ev) => { });
            });
            alert.SetButton2("Edit", (c, ev) =>
            {
                StartActivity(new Intent(this, typeof(MainActivity)));
            });
            alert.SetButton3("Cancel", (c, ev) => { });

            alert.Show();

However in the code above when I press the "Delete" button the reminder is not deleted.

Any help appreciated!

d51
  • 316
  • 1
  • 6
  • 23
  • The reason it's not working is that you using the same instance twice, `AlertDialog alert = dialog.Create();` this needs to be called every time you want to create an alert. – FreakyAli Nov 10 '20 at 03:50
  • @FreakyAli thanks a lot, it is working now. You should make it as an answer, I would happily give you the upvote :) – d51 Nov 10 '20 at 04:16

1 Answers1

1

The reason it's not working is that you're using the same instance twice, AlertDialog alert = dialog.Create(); this needs to be called every time you want to create an alert.

        AlertDialog alert = dialog.Create();
FreakyAli
  • 13,349
  • 3
  • 23
  • 63