80,354
社区成员
发帖
与我相关
我的任务
分享
private class DoubleTextWatcher implements TextWatcher {
private EditText mEditText;
public DoubleTextWatcher(EditText e) {
mEditText=e;
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
public void afterTextChanged(Editable s) {
}
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
String content = s == null ? null : s.toString();
if(s == null || s.length() == 0) {
return;
}
int size = content.length();
if(!content.endsWith(".")) { //最后输入的不是点,无需处理
return;
}
if(content.substring(0, size - 1).contains(".")) { //判断之前有没有输入过点
s.delete(size-1, size);//之前有输入过点,删除重复输入的点
}
}