Ziv Sion
Ziv Sion

Reputation: 165

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

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?

Upvotes: 1

Views: 309

Answers (1)

Cyb3rKo
Cyb3rKo

Reputation: 464

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.

Upvotes: 0

Related Questions