我有两个EditText,一个用于输入密码,另一个用于确认此密码。这些编辑文本的最大长度为5。
confirmPwdEdiText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) { }
public void onTextChanged(CharSequence charSequence, int start, int before, int count)
{
String pwd = passwordEdiText.getText().toString();
String confirmaion = charSequence.toString();
if ((pwd == null || pwd.trim().length() <= 0) && confirmaion.trim().length() > 0) {
Toast.makeText(context,"Enter password",Toast.LENGTH_SHORT).show();
}
else if (pwd != null && pwd.trim().length() > 0 ) {
if(confirmaion.trim().length() == pwd.length()) {
if (pwd.equals(confirmaion)) {
password = pwd;
Toast.makeText(context,"Passwords match",Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(context,"Passwords do not match",Toast.LENGTH_SHORT).show();
}
}
}
}
});
当我使用此密码确认密码时,删除密码时会再次显示'密码不匹配'吐司。如何有效地确认密码不使用按钮点击或任何其他方法>?]
预先感谢
我有两个EditText,一个用于输入密码,另一个用于确认此密码。这些编辑文本的最大长度为5。ConfirmPwdEdiText.addTextChangedListener(new TextWatcher(){public void ...
您可以使用TextWatcher
@Override
public void afterTextChanged(Editable s) {
System.out.println(s.toString());
String oldPass = oldPassword.getText().toString();
String newPass = newPassword.getText().toString();
String confirmPass = confirmPassword.getText().toString();
if (!oldPass.equals("") && !newPass.equals("") && oldPass.equals(newPass)) {
Toast.makeText(getContext(), "Choose Different Password than Old Password", Toast.LENGTH_SHORT).show();
}
else if (!newPass.equals("") && !confirmPass.equals("") && !newPass.equals(confirmPass) && newPass.length()==confirmPass.length())
{
Toast.makeText(getContext(), "Choose same as New Password", Toast.LENGTH_SHORT).show();
}
}