80,493
社区成员
发帖
与我相关
我的任务
分享
oldPasswordEdit.addTextChangedListener(new TextWatcher()
{
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count)
{
Log.info(TAG,
s.toString() + " " + start + " " + before + " "
+ count);
// 判断最后一位如果不是符合输入den 让该值等于之前的
int charInt;
String password = s.toString();
if (null != password)
{
int inputLength = password.length();
if (null != oldPassword)
{
if (password.length() - oldPassword.length() > 0)
{
StringBuffer sb = new StringBuffer();
for (int i = 0; i < password.length(); i++)
{
charInt = password.codePointAt(i);
Log.info(TAG,
"1----" + charInt + "----------");
if ((charInt >= 33 && charInt <= 126)
&& !(charInt < 33 || charInt == 38
|| charInt >= 60 && charInt <= 63
|| charInt >= 91 && charInt <= 93
|| charInt >= 123 && charInt <= 125 || charInt > 126))
{
sb.append(password.charAt(i));
}
}
password = sb.toString();
oldPasswordEdit.setText(password);
if (password.length() == inputLength)
{
oldPasswordEdit.setSelection(start + count);
}
else
{
oldPasswordEdit.setSelection(start);
}
}
}
}
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after)
{
oldPassword = s.toString().trim();
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s)
{
Log.info(TAG,
s.toString());
// TODO Auto-generated method stub
}
});
newPasswordEdit.addTextChangedListener(new TextWatcher()
{
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count)
{
Log.info(TAG,
s.toString() + " " + start + " " + before + " "
+ count);
// 判断最后一位如果不是符合输入den 让该值等于之前的
int charInt;
String password = s.toString();
if (null != password)
{
int inputLength = password.length();
if (null != newBeforChange)
{
if (password.length() - newBeforChange.length() > 0)
{
StringBuffer sb = new StringBuffer();
for (int i = 0; i < password.length(); i++)
{
charInt = password.codePointAt(i);
Log.info(TAG,
"1----" + charInt + "----------");
if ((charInt >= 33 && charInt <= 126)
&& !(charInt < 33 || charInt == 38
|| charInt >= 60 && charInt <= 63
|| charInt >= 91 && charInt <= 93
|| charInt >= 123 && charInt <= 125 || charInt > 126))
{
sb.append(password.charAt(i));
}
}
Log.info(TAG,
"-----已替换 " + sb.toString() + "----------");
password = sb.toString();
newPasswordEdit.setText(password);
if (password.length() == inputLength)
{
newPasswordEdit.setSelection(start + count);
}
else
{
newPasswordEdit.setSelection(start);
}
}
}
}