EditText input filter that causes duplicate letters

I limited the input of my edittext as follows:

InputFilter filter = new InputFilter() { 
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
            String output = "";
            for (int i = start; i < end; i++) {
                if (source.charAt(i)!='~'&&source.charAt(i)!='/') {
                    output += source.charAt(i); 
                }
            } 
            return output;
        }
    };

But anyone who has used this method will know that it causes repeated characters when it is mixed with auto-correction and the backspace keyword. To solve this problem, I removed the auto-correction from the keyboard as follows:

Edittect.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

Now it works perfectly on the Android keyboard, but the problem is with alternative keyboards (from the Google game), this does not disable the automatic fix, and therefore I again encountered the problem of repeating characters. Has anyone come across this / knew how to solve it?

+5
source share
1 answer

EDIT - . (, samsungs) - .

, .

:

  • android:digits xml
  • edittext, ,
  • , , - , .

-

InputFilter() {
@Override
public CharSequence filter(CharSequence source, int start, int end,
        Spanned dest, int dstart, int dend) {

    if (source instanceof SpannableStringBuilder) {
        SpannableStringBuilder sourceAsSpannableBuilder = (SpannableStringBuilder)source;
        for (int i = end - 1; i >= start; i--) { 
            char currentChar = source.charAt(i);
             if (currentChar=='/' || currentChar=='~') {    
                 sourceAsSpannableBuilder.delete(i, i+1);
             }     
        }
        return source;
    } else {
        StringBuilder filteredStringBuilder = new StringBuilder();
        for (int i = 0; i < end; i++) { 
            char currentChar = source.charAt(i);
            if (currentChar != '~'|| currentChar != '/') {    
                filteredStringBuilder.append(currentChar);
            }     
        }
        return filteredStringBuilder.toString();
    }
}
}
+4

All Articles