【发布时间】:2013-03-06 09:33:12
【问题描述】:
我有两个编辑文本,一个用于输入密码,另一个用于确认此密码。这些编辑文本的最大长度为 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();
}
}
}
}
});
当我使用它来确认密码时,删除密码时再次显示“密码不匹配”吐司。如何以有效的方式确认密码不使用按钮单击或任何其他方式?
提前致谢
【问题讨论】:
-
用于将密码存储在共享首选项中并使用共享首选项文件检查按钮单击。
-
对不起。我编辑了我的代码。请检查它。如何使用 TextWatcher 确认密码?
-
用 charSequence 替换 pwd...bcz 这个你的字符串
标签: android passwords password-confirmation