输入一个字显示后有两个(在EditText框里组拼中文)

q5351818 2012-04-07 12:37:38
oldPasswordEdit 和 newPasswordEdit 都是EditText控件






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);
}
}
}
}








输入一个一个的字符 输入一串中文 拼音没问题 就是在框里用在拼音组成一个汉字的时候 组成不了汉字 而且输入一个字母 就会变成两个字母 比如用这种模式输入 j 则会自动变成 jj 再输入一个u 则变成jjuu 郁闷死呢
...全文
143 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
q5351818 2012-04-07
  • 打赏
  • 举报
回复
别看注释噢 是以前 遗留下来的

80,493

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧