Android Studio Throws an error if a user reaches the character limit

278 Views Asked by At

I used the maxLength method. I want you to be notified "Limit characters here are 10 characters" I know the user can't add characters anyway, but I still want to be notified. How do i get when the user is still trying to add characters to throw him an error?

1

There are 1 best solutions below

0
Cyb3rKo On BEST ANSWER

I suppose you are talking about an EditText view.
Which one do you use? The Android widget one or the Material one?

Because the Material TextField (https://material.io/develop/android/components/text-fields) has an easy to use character counter:

Google Material docs


If you then want to additionally show an error (e.g. with a Toast) you can get the max length counter by calling yourTextInputLayout.getCounterMaxLenght and check it.