【问题标题】:How to show an Alert PopUp from an Alert PopUp in Xamarin android如何在 Xamarin android 中显示警报弹出窗口中的警报弹出窗口
【发布时间】:2020-11-10 02:39:04
【问题描述】:

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

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

类似这样的:

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(); 每次你想创建警报时都需要调用它。
  • @FreakyAli 非常感谢,它现在正在工作。你应该把它作为答案,我很乐意给你投票:)

标签: c# android xamarin android-alertdialog


【解决方案1】:

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

        AlertDialog alert = dialog.Create();

【讨论】:

    猜你喜欢
    • 2012-01-29
    • 1970-01-01
    • 1970-01-01
    • 2013-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-05
    • 2014-06-02
    相关资源
    最近更新 更多