Así es como logro crear una ventana emergente persistente al cambiar la contraseña.
// Login Activity
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.SetIcon(Resource.Drawable.padlock);
alert.SetCancelable(false);
var changepass = LayoutInflater.From(this);
var changePassLayout = changepass.Inflate(Resource.Layout.ChangePasswordLayout, null);
alert.SetView(changePassLayout);
txtChangePassword = (EditText)changePassLayout.FindViewById(Resource.Id.txtChangePassword);
txtChangeRetypePassword = (EditText)changePassLayout.FindViewById(Resource.Id.txtChangeRetypePassword);
alert.SetPositiveButton("Change", delegate {
// You can leave this blank because you override the OnClick event using your custom listener
});
alert.SetNegativeButton("Cancel", delegate {
Toast.MakeText(this, "Change password aborted!", ToastLength.Short).Show();
});
AlertDialog changePassDialog = alert.Create();
changePassDialog.Show();
// Override OnClick of Positive Button
Button btnPositive = changePassDialog.GetButton((int)Android.Content.DialogButtonType.Positive);
btnPositive.SetOnClickListener(new CustomListener(changePassDialog, empDetailsToValidate.EmployeeID));
// My Custom Class
class CustomListener : Java.Lang.Object, View.IOnClickListener, IDialogInterfaceOnDismissListener
{
AlertDialog _dialog;
EditText txtChangePassword;
EditText txtChangeRetypePassword;
EmployeeDetails _empDetails;
string _workingEmployeeID;
public CustomListener(AlertDialog dialog, string employeeID)
{
this._dialog = dialog;
this._workingEmployeeID = employeeID;
}
public void OnClick (View v)
{
_empDetails = new EmployeeDetails(v.Context);
txtChangePassword = (EditText)_dialog.FindViewById (Resource.Id.txtChangePassword);
txtChangeRetypePassword = (EditText)_dialog.FindViewById (Resource.Id.txtChangeRetypePassword);
if (!(txtChangePassword.Text.Equals(txtChangeRetypePassword.Text))) {
Show();
Toast.MakeText(v.Context, "Password not match.", ToastLength.Short).Show();
} else if (txtChangePassword.Text.Trim().Length < 6) {
Show();
Toast.MakeText(v.Context, "Minimum password length is 6 characters.", ToastLength.Short).Show();
} else if ((txtChangePassword.Text.Equals(LoginActivity.defaultPassword)) || (txtChangePassword.Text == "" || txtChangeRetypePassword.Text == "")) {
Show();
Toast.MakeText(v.Context, "Invalid password. Please use other password.", ToastLength.Short).Show();
} else {
int rowAffected = _empDetails.UpdatePassword(_workingEmployeeID, SensoryDB.PassCrypto(txtChangePassword.Text, true));
if (rowAffected > 0) {
Toast.MakeText(v.Context, "Password successfully changed!", ToastLength.Short).Show();
_dialog.Dismiss();
} else {
Toast.MakeText(v.Context, "Cant update password!", ToastLength.Short).Show();
Show();
}
}
}
public void OnDismiss (IDialogInterface dialog)
{
if (!(txtChangePassword.Text.Equals (txtChangePassword.Text))) {
Show();
} else {
_dialog.Dismiss();
}
}
public void Show()
{
_dialog.Show();
}
}
Por cierto, yo uso Mono para Android no Eclipse.
Pregunta similar: http://stackoverflow.com/questions/2620444/android-how-to -prevent-dialog-closed-or-remain-dialog-when-button-is-clicked –
en la pantalla de inicio de sesión después de enviar los datos de inicio de sesión basados en la respuesta, mostrando alerta con una vez más el nombre de usuario para confirmar y aceptar y cancelar los botones de la interfaz de diálogo. si el usuario no ingresa nada en el cuadro de diálogo y hace clic en ok, la ventana de diálogo se descarta, incluso no es para escribir. Una vez que haya verificado la validación, vacíela o no. Solo descarte si no está vacía. Otra pantalla muestra el error en edittext. Ayúdenme a hacerlo en diferentes formas desde el último día en adelante – Harsha
Sería mejor [desactive el botón hasta que el usuario esté listo para continuar] (http://stackoverflow.com/a/40669929/3681880) en lugar de evitar que el diálogo se cierre después de que el usuario ya haya hecho clic en el botón. – Suragch