Android modal AlertDialog

LolocasLolocas Lolo CasFRMember

Hi

Is there a way to perform a Modal dialog on Android like in .NET

DialogResult myDialogResult = MessageBox.Show("My text", "My caption", MessageBoxButtons.YesNoCancel);

In Android when i called alertDialog.Show() the execution of program doesn't stop.

  • I try to Use Android.OS.Looper.Loop(), it works but i don't know how to exit with it.
  • I try to Use
    var are = new System.Threading.AutoResetEvent(false);
    are.WaitOne();
    But the dialog is not displayed.

Thanks in advanced

Posts

  • JoeJoe Joseph Phillips AUMember

    You don't want to block the UI thread. It handles handles the events from your dialog.

    What specifically are you trying to prevent from executing while the dialog is active?

  • LolocasLolocas Lolo Cas FRMember

    Hi, thanks for your answer

    I want to do something like this

    if (Dialog.ShowYesNo() == "YES")
    {
    // Action
    return true;
    }
    else
    return false;

    If possible i don't want to use Callback

  • TeHaTeHa Tobias Heller DEMember ✭✭

    I've got the same problem a time ago and that's why I derive my own MessageBox-class from alertDialog and added a Result-Event.

    After the UI has called the MsgBox the UI can stop working and continue after receive the result-event.

  • MassimilianoFabbriMassimilianoFabbri Massimiliano Fabbri USMember

    @TeHa Can u share this class ? I need to know ho to do a Modali Dialog.
    a way to have the app wait for the user input:

    var builder = new AlertDialog.Builder(this);
    builder.SetTitle("Operation confirmation");
    builder.SetMessage ("Continue with " + cmd + " command?");
    builder.SetPositiveButton("Yes", (sender, args) => { /* do stuff on OK */ });
    builder.SetNegativeButton("No", (sender, args) => { cmd="cancel"; });
    builder.SetCancelable(false);
    builder.Show ();
  • TeHaTeHa Tobias Heller DEMember ✭✭

    @MassimilianoFabbri:

    Sry, but I can't! It's very long ago and don't find this class anymore BUT I think it was anyway slightly oversized, means:

    You can do the same by calling the UI to proceed in the positive-button event. May look like this:

    private void someMethod()
    {
    // ...
    // Do some stuff on UI
    // Build the Dialog ...
    builder.SetPositiveButton(GetString(Android.Resource.String.Yes), (sender, args) => { ResumeAfterDialog(); });
    builder.Show();
    // Don't do anything more
    }

    private void ResumeAfterDialog()
    {
    // go on
    }

    PS: You can use android default strings for dialog buttons -> GetString(Android.Resource.String.Yes)

Sign In or Register to comment.