Why does EditText repeat the text when I enter an invalid char defined by the android: digits attribute?

My Activity has an EditText as follows:

 <EditText android:id="@android:id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="text" android:digits="0123456789.:" /> 

Allowed entry must be . , : and numbers . But if not allowed char is entered when the EditText empty, the text starts to duplicate.

For example, if EditText empty, enter the following sequence: abc123 .

On my device, the result is 1112123 , but the expected result should be just 123 .

Since this should be as simple as possible, I would not want to use an InputFilter .

+6
source share
1 answer

Actually, this is related to the default InputFilter for android:digits ( DigitsKeyListener ), android:inputType="text" and the current Keyboard .

Keyboard suggestions can be messy when using android:digits . Since I don't need keyboard suggestions for this particular EditText , I changed android:inputType to textNoSuggestions , and now it works as expected.

+5
source

Source: https://habr.com/ru/post/974326/


All Articles