英文:
Android Studio Throws an error if a user reaches the character limit
问题
我使用了maxLength
方法。我希望您被通知“此处限制字符为10个字符”。
我知道用户无论如何都无法添加字符,但我仍然希望收到通知。
当用户仍在尝试添加字符时,如何获得通知以抛出错误?
英文:
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
得分: 0
我猜你在谈论一个 EditText 视图。
你使用哪个?Android 的小部件还是 Material 的?
因为 Material TextField(https://material.io/develop/android/components/text-fields)有一个易于使用的字符计数器:
如果你还想额外显示错误(例如使用 Toast),你可以通过调用 yourTextInputLayout.getCounterMaxLength
来获取最大长度计数器并进行检查。
英文:
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:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论