EditText限制文字输入

来源:互联网 发布:双管德林杰分解数据图 编辑:程序博客网 时间:2024/04/30 15:26
private final TextWatcher mTextWatcher = new TextWatcher() {    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) {        if (s.length() > 0) {            int pos = s.length() - 1;            char c = s.charAt(pos);            if (c == '\'') {                s.delete(pos,pos+1);                Toast.makeText(MyActivity.this, "Error letter.",Toast.LENGTH_SHORT).show();            }        }    }};EditText mEditor = (EditText)findViewById(R.id.editor_input);mEditor.addTextChangedListener(mTextWatcher);