我创建了一个Alert Popup,询问用户是否要编辑或删除提醒。
如果用户单击删除提醒按钮,我想显示另一个警报弹出窗口,询问用户是否确定。
类似这样的东西:
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();