Cancelling a ProgressDialog

Could anyone help me use the following Android code in MfA please:

            progressDialog = Android.App.ProgressDialog.Show(this, "Searching ", "Please wait...");
            progressDialog.SetCancelable(true);
            progressDialog.SetOnCancelListener(new OnCancelListener()
            {
                public void onCancel(DialogInterface dialog) 
                {
                  finish(); //If you want to finish the activity.
                }
            });

Thanks...Andrew

Posts

  • Never mind. Figured it out by creating and using a new class:

    public class ProgressDialogCancel : Java.Lang.Object, IDialogInterfaceOnCancelListener

    Andrew

  • WeiHoeWeiHoe MYMember

    Hi,

    Able to show us the sample code how to achieve this?

  • CortezCortez USMember ✭✭✭

    Dear @was!

    I think in MfA ( Mono for Android? ) you have events too for ProgressDialog. For example:

    `ProgressDialog dialog = new ProgressDialog(this);
    dialog.DismissEvent += (object sender, EventArgs e) =>
    {
    Finish();
    };

    // or
    dialog.CancelEvent += (object sender, EventArgs e) =>
    {
    }`

    I think it is neccessary to set Cancelable true as in the sample code what you inserted.

  • Hi WeiHoe,

    Like this:

    var progressDialog = Android.App.ProgressDialog.Show(this, "Searching for Android Conduit", "Please wait...");
                        progressDialog.SetCancelable(true);
                        progressDialog.SetCanceledOnTouchOutside(false);
                        progressDialog.SetOnCancelListener(new ProgressDialogCancel(this, this));
    

    and:

     public class ProgressDialogCancel : Java.Lang.Object, IDialogInterfaceOnCancelListener
            {
                private Context _context;
                private readonly Activity _activity;
    
                public ProgressDialogCancel(Context context, Activity activity)
                {
                    _context = context;
                    _activity = activity;
                }
    
                public void OnCancel(IDialogInterface dialog)
                {
                    _activity.OnBackPressed();
                }
            }
    
  • WeiHoeWeiHoe MYMember

    Hi Was,

    Thanks a lot

Sign In or Register to comment.