I have an EditTextPreference set up with a filter to limit it's size, like so:
pref.setOnBindEditTextListener(new EditTextPreference.OnBindEditTextListener() {
@Override
public void onBindEditText(@NonNull EditText editText) {
editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(10)});
}
});
I want to also limit it to only accept letters (not just a-zA-Z, since the app accepts more than one language). How can I go about doing this?
I have tried many filters before, including all of those suggested in these questions and similar:
Making an EditText field accept only letters and white spaces in Android
Edittext only allow letters (programmatically)
With filters like those, whenever a number is inputted and then a letter, I get issues like:
- The whole text disappears
- The whole text gets duplicated
- The last few characters get duplicated
I also tried changing the XML by adding and android:digits
, but no matter what it doesn't restrict the input at all.
Every inputType
I've tried so far does not restrict the keyboard to only letters.
EDIT: I figured it out, answer below.