如何从 Xamarin 中的警报弹出窗口显示警报弹出窗口 android

How to show an Alert PopUp from an Alert PopUp in Xamarin android

我创建了一个提醒弹出窗口,询问用户是要编辑还是删除提醒。

如果用户点击删除提醒按钮,我想显示另一个警告弹出窗口,询问用户是否确定。

像这样:

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();

但是在上面的代码中,当我按下“删除”按钮时,提醒并没有被删除。

感谢任何帮助!

它不起作用的原因是您两次使用同一个实例,AlertDialog alert = dialog.Create();每次你想创建警报时都需要调用它。

        AlertDialog alert = dialog.Create();