簡體   English   中英

如何從 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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM