Set dynamically digits for EditText - Android

437 Views Asked by At

I want to limit an EditText field to English characters and numbers only.

I can do this in the xml section as follows

android:digits = "..."

and dynamically as follows;

editText.keyListener = DigitsKeyListener.getInstance(Util.ENGLISH_LANGUAGE_DIGITS)

However, only a keyboard with numbers appears, so there is no clickable letter but digits work correctly (I tested with copy paste).

Problem: Both the letter and the number should appear on the keyboard.

editText.keyListener = DigitsKeyListener.getInstance(Util.ENGLISH_LANGUAGE_DIGITS)
editText.inputType = InputType.TYPE_CLASS_TEXT

I tried this but it loses its DigitsKeyListener feature.

1

There are 1 best solutions below

0
Ümit Bülbül On BEST ANSWER

Solution

editText.keyListener = DigitsKeyListener.getInstance(Util.ENGLISH_LANGUAGE_DIGITS)
editText.setRawInputType(InputType.TYPE_CLASS_TEXT)