1

Here is my EditText in xml layout:

<EditText 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:maxLength="2"
    android:maxLines="1"/>

This EditText length limitation (maxLength="2") works just partially.

It looks like user can't enter more than 2 characters because more is not shown, but in practise after pressing character "A" on keyboard 5 times he needs to press "back" (on keyboard) 4 times to delete second character and that makes no sense at all.

Funny enough this works correctly (as expected) with digits.

P.S. Already checked few question related questions like this and this but those solutions are not working

Community
  • 1
  • 1
Ewoks
  • 12,285
  • 8
  • 58
  • 67

1 Answers1

2

Basically auto-suggestion on keyboard app is the source of messing this up, so characters need to be "deleted" even when they are not displayed. This doesn't happen with numbers because auto-suggestion can not really suggest something based on "23", no?

Anyways, solution is to add following attribute/value to your EditText:

android:inputType="textNoSuggestions"

In theory you can combine this with other inputTypes, for example:

android:inputType="textCapCharacters|textNoSuggestions"

Hope I helped somebody facing this issue.. Enjoy programming ;)

Ewoks
  • 12,285
  • 8
  • 58
  • 67
  • just for records, I still find this weird so anyone who understands reasons behind it better feel free to advice or propose better solution – Ewoks Oct 04 '18 at 07:26