EditText android: maxLength write up to 10 characters

1

The theme is as follows, I have an EditText

 <EditText
                android:id="@+id/txtBeneficiary"
                android:inputType="phone"
                android:maxLength="10"
                android:layout_width="160dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:textSize="@dimen/simple_text_size"
                android:textColor="@color/light_grey"/>

Clearly lets you write up to 10 characters,

But in my application I have a button which brings you the contacts and you can choose one, when you choose I show the name and number the number and then I get that number for later, the problem comes in that if the name is longer than 10 I have the name cut, do I have any way to get the restriction for him momentarily? or there is an optimal way to do this without having to remove the restriction  

    
asked by Bruno Sosa Fast Tag 28.12.2017 в 21:04
source

1 answer

1

To allow you to bring a length greater than 10 characters you must remove the restriction:

android:maxLength="10"

But you can add a filter that allows you to write only 10 characters, but before defining it it is important to write the name so that it is displayed complete.

    InputFilter[] FilterArray = new InputFilter[1];
    FilterArray[0] = new InputFilter.LengthFilter(10);
    myEditText.setFilters(FilterArray);
    
answered by 28.12.2017 / 22:54
source