Android Studio如果用户达到字符限制,会抛出错误。

huangapple go评论89阅读模式
英文:

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)有一个易于使用的字符计数器:

Android Studio如果用户达到字符限制,会抛出错误。


如果你还想额外显示错误(例如使用 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:

Android Studio如果用户达到字符限制,会抛出错误。


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.

huangapple
  • 本文由 发表于 2020年10月27日 02:07:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/64542665.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定