1

I have an EditText which simply should disallow typing specific letters. I have made a variable string with the accepted digits as follows: <string name="accepted_digits">ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&amp;-,\'</string>

My EditText looks like this:

 <EditText
        android:id="@+id/test_editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="text"
        android:digits="@string/accepted_digits"
        />

Now when I type an accepted digit followed by any digit not in the accepted_digits string it produces a weird behaviour i.e

1st input = M | Displayed: M

2nd input = æ | Displayed: MM

3rd input = l | Displayed: MMMlMl

4th input = k | Displayed: MMMlMlMlk

I did not intend this behaviour - I intended that an unaccepted digit would simply be skipped so my displayed input would be: Mlk.

I have tried simply changing the inputType to android:inputType="textVisiblePassword but I would like autosuggestion to be allowed.

Any help is appreciated.

ZooMagic
  • 616
  • 7
  • 15

1 Answers1

1

You are mixing characters with digits. A digit is a character which has a numerical value while a character can be anything. In order to fix this you can not use android:digits but you can use TextWatcher. See Android: How can I validate EditText input?

Murat Karagöz
  • 35,401
  • 16
  • 78
  • 107