我設置TextWatcher
到EditText
像下面。但是當我嘗試清除文本時,光標將在清除每個字母后開始。EditText - 光標即將開始爲明文時的每個字母
class MyInputWatcher implements TextWatcher {
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
et.removeTextChangedListener(watcher2);
et.setText(s.toString().replaceAll("[^[:alpha:]]", ""));
et.addTextChangedListener(watcher2);
}
@Override
public void afterTextChanged(Editable s) {
}
}
裏面使用'afterTextChanged' – W4R10CK