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

时间:2020-11-10 02:39:04

标签: c# android xamarin android-alertdialog

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

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

类似这样的东西:

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

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

任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:1)

它不起作用的原因是您使用了两次相同的实例,AlertDialog alert = dialog.Create();。每当您要创建警报时都需要调用此方法。

        AlertDialog alert = dialog.Create();