这是我如何设法在更改密码时创建持久弹出窗口。
// 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();
}
}
BTW,我使用单声道的Android不蚀。
类似的问题:http://stackoverflow.com/questions/2620444/android-how-to在发送基于响应的登录细节之后,当显示警报并再次询问用户名以确认并确认并取消对话界面按钮时,在登录屏幕上点击 - 预防对话框 - 关闭或者剩余对话框 - 当按钮被点击 – 2012-06-14 16:48:20
时。如果用户没有在对话框中输入任何东西,并点击确定提醒对话框甚至不写我dismiss.once我需要检查验证为空或不是然后才解雇,如果不是空的其他明智的显示seterror上edittext请帮我做不同的方式从最后一天起 – Harsha 2016-07-18 05:35:06
这会更好[禁用按钮,直到用户准备好继续](http://stackoverflow.com/a/40669929/3681880),而不是阻止用户点击按钮后关闭对话框。 – Suragch 2016-11-18 06:14:02