EditText and InputFilter cause repeating text

前端 未结 5 1922
野性不改
野性不改 2021-02-19 05:43

I\'m trying to implement an EditText that limits input to alpha chars only [A-Za-z].

I started with the InputFilter method from this post. When I type \"a%\" the text d

5条回答
  •  你的背包
    2021-02-19 06:11

    Use the following code:

    EditText input = (EditText) findViewById(R.id.inputText);
       input.addTextChangedListener(new TextWatcher() {
    
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub
             for( int i = start;i

    If you want the valid text to remain in the EditText:


     input.addTextChangedListener(new TextWatcher() {
    
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub
    
        }
    
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub
    
        }
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
             for( int i = 0;i

提交回复
热议问题