1

I have an auto complete text view and its max length is defined in xml file as below.

<AutoCompleteTextView
android:id="@+id/autocompleteTextView"
fontPath="font/Roboto-Regular.ttf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="12"
android:inputType="number"
android:maxLength="12"
android:maxLines="1" />

but when I select values from suggestions based on my input it still allow me to enter more than 12 numbers. I am using text watcher for auto complete suggestions. How to resolve this problem?

jil123
  • 99
  • 1
  • 12
  • check this link https://stackoverflow.com/questions/21718733/edit-text-max-length-and-show-the-length-in-the-texview – Lingeshwaran Apr 18 '18 at 12:21

1 Answers1

1

Please try below example code and change textview names as per you required.

In Java file or Activity -

@BindView(R.id.tvName)
    AutoCompleteTextView tvName;

        int maxLength = 12;
        InputFilter[] fArray = new InputFilter[1];
        fArray[0] = new InputFilter.LengthFilter(maxLength);
        tvName.setFilters(fArray);

In .xml file :-

<AutoCompleteTextView
        android:id="@+id/tvName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Please enter"/>
Janvi Vyas
  • 732
  • 5
  • 16