I need to run some code where my alert dialog gets closed other then by just dismissing it via clicking on the buttons. The user can close a dialog by clicking somewhere on the activity in the background.
I've managed to get this to work like here:
private void InfoAlert()
{
alert = new Android.App.AlertDialog.Builder(this);
alert.SetTitle(Resources.GetString(Resource.String.HiThere));
alert.SetMessage(Resources.GetString(Resource.String.BetaGame));
alert.SetNeutralButton(Resources.GetString(Resource.String.GotIt), (senderAlert, args) =>
{
var activity2 = new Intent(this, typeof(Activity_Login));
StartActivity(activity2);
Finish();
});
alert.SetOnCancelListener(new ProgressDialogCancel(this, this));
Dialog dialog = alert.Create();
dialog.Show();
}
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_AcctCreationLogin.btnInsta.Visibility = ViewStates.Visible;
Activity_AcctCreationLogin.btnFB.Visibility = ViewStates.Visible;
Activity_AcctCreationLogin.btnCreateAccount.Visibility = ViewStates.Visible;
Activity_AcctCreationLogin.btnExplain.Visibility = ViewStates.Visible;
Activity_AcctCreationLogin.btnLogin.Visibility = ViewStates.Visible;
Activity_AcctCreationLogin.ln1.SetBackgroundResource(0);
Activity_AcctCreationLogin.ln1.SetBackgroundColor(Color.ParseColor("#ffffff"));
Activity_AcctCreationLogin.alert.Dispose();
}
}
But since I would need to run so much code from the other class, this is a very unclean solution. Idealy, there would be a way of doing it like this:
alert.SetOnCancelListener += delegate
{
//do something
};
How would I achieve something like this?
Thanks :)