Edittext Android Accents

Asked

Viewed 829 times

2

someone there knows how I can and if you can do the following, in my Edittext wish the user could not put accents.

In case it would be better to treat the text and remove after typing?

  • Could you put some part of your code? What have you tried to do...

  • Actually, I didn’t know where to begin, but Fernando’s response helped!

1 answer

1


Solution 1 (InputFilter)

You can use InputFilter to that end, the implementation being something like this:

InputFilter filter = new InputFilter() {
    public CharSequence filter(CharSequence source, int start, int end,
                               Spanned dest, int dstart, int dend) {
        for (int i = start; i < end; i++) {
            // Não tenho certeza se esse método "Character.isLetterOrDigit" restringe todos os acentos como você espera, mas no seu caso você pode substitui-lo pelo seu método.
            if (!Character.isLetterOrDigit(source.charAt(i))) {
                return "";
            }
        }
        return null;
    }
};
editText.setFilters(new InputFilter[] { filter });

Solution 2 (digits of EditText)

Another possibility is you inform which entries you allow in the attribute digits of EditText, may be something similar to this:

<EditText
    android:inputType="text"
    android:digits="0123456789qwertzuiopasdfghjklyxcvbnm" />

Browser other questions tagged

You are not signed in. Login or sign up in order to post.