Awaiting Pop up in case of Multiple Popup Scenarios in Xamarin Android

I have a popup, let me call it "Warning Popup" with two buttons Yes and No and some event associated to it. Only after executing any one of the event, I want to display another popup (Success PopUp). But currently, the Success Popup gets displayed over Warning Popup together, which does not allow me to click any of the YES/NO button from Warning popup.

I have tried all possible ways :- 1) awaited the event associated with Popup 2) awaited the popup call 3) awaited the method which calls the popup fragment from it's respective class. None of them worked.

if(some condition){
//
}
else{
ForceAcceptanceMessageFlag = true;
EventHandler<WarningEventArgs> forceAcceptanceEvent = (sender, e) => PerformForceAcceptanceAsync(tempGoodsItemsList);
string warningMsg = "SOME WARNING";
ShowWarningDialog(AppResources.Error, warningMsg, AppResources.OK, AppResources.Cancel,
 forceAcceptanceEvent, new EventHandler<WarningEventArgs>(NoButtonClicked)).Wait();
}

 private async void PerformForceAcceptanceAsync(ObservableCollection<FOHItem> looseGoodsItemsList)
{
   // some code
}

protected void NoButtonClicked(object sender, WarningEventArgs warningEventArgs)
{
    PopupNavigationService.Dismiss(ViewModelLocator.KEY_POPUP_WARNING);
}

Could someone help me with this scenario as I don't want to introduce some flags as there are a lot of other complex flows.

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai

    What method did you use to achieve pop up? I created a basice demo using AlertDialog, move the success_dialog.Show() method to warning_dialog's click event. See as below:

    public class MainActivity : AppCompatActivity
    {
        Dialog success_dialog;
        Android.App.AlertDialog.Builder alert2;
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);
    
            Initilize_information();
    
            FindViewById<Button>(Resource.Id.alert_btn).Click += delegate
            {
                Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(this);
                alert.SetTitle("Warning Popup");
                alert.SetMessage("A basic dmeo about testing Popup's click event");
                alert.SetNeutralButton("No", delegate { });
                alert.SetPositiveButton("Yes", (senderAlert, args) =>
                {
                    success_dialog.Show();
                });
    
                Dialog warning_dialog = alert.Create();
                warning_dialog.Show();
            };
        }
        ...
    }
    

  • PoorneshV15PoorneshV15 Member ✭✭

    In my case the PopUp is a different Fragment.

  • JarvanJarvan Member, Xamarin Team Xamurai

    Detect the popup's button click event. Call the command of showing the Success_Popup when clicking button.

    public class DialogClass : DialogFragment
    {
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = inflater.Inflate(Resource.Layout.dialog_fragment, container, false);
    
            Button btn = view.FindViewById<Button>(Resource.Id.PostiveButton);
            btn.Click += delegate
            {
                Dismiss();
                FragmentTransaction fragmentTransaction = FragmentManager.BeginTransaction();
                DialogClass_2 dialogClass = new DialogClass_2();
                dialogClass.Show(fragmentTransaction, "dialog");
            };
    
            return view;
        }
    }
    
Sign In or Register to comment.