javaandroidxmlandroid-textwatchercharactercount

How can I show in UI the limit of character and how much was digited for the user? Android Java


How can I do that? I mean showing the limit of character and how much was digited on the input text.

EditText Character UI


Solution

  • You can simply use TextInputLayout widget for this task in your xml,

    <android.support.design.widget.TextInputLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:counterEnabled="true"
        app:counterMaxLength="50">
    
           <EditText
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:maxLength="50" />
    
    </android.support.design.widget.TextInputLayout>
    

    Here counterEnabled is to enable counter, and counterMaxLength sets the maximum range of counter.

    While maxLength in EditText sets the maximum number of characters, can be enters in your EditText.