android-edittextdigitsandroid-inputtype

Set dynamically digits for EditText - Android


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.


Solution

  • Solution

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