阻止用户在编辑框中输入内容?
如果输入文本长度超过 10,我希望 EidtText 停止接受用户的输入..但它应该能够删除 EditText 中已有的文本,即使文本长度超过 10 ...
可以吗?请帮我解决代码..
谢谢:)
i want the EidtText to stop accepting input from the user if the input text length is more than 10 ..but it should be able to delete the already available text in the EditText even though the text length is more than 10 ...
can some one help me with the code pls..
thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过限制 EditText 的字符数?
Have you tried limiting the number of character of the EditText ?
If not take a look at this
使用EditText的setKeyListener方法设置自定义KeyListener,限制控件中文本的长度
Use EditText's setKeyListener method to set a custom KeyListener that limits the length of the text in the control
供参考:
如果我想跟踪不止一种类型的最大限制(多字段共享最大限制、单个字段最大限制),我会查看编辑中的选择位置。
如果位置大于我的最小最大值,我只取左边的最大字符。
如果该位置小于我的最大值,我将获取左侧位置的字符,从最大值中减去该位置的字符,然后获取剩余的右侧字符。
仅当您有多个可能的限制器时才需要执行此操作。
For reference:
In cases where I want to track more than one type of max limit (multiple field shared max limit, individual field max limit), I look at the selection position in the edit.
If the position is larger than my smallest max value, I just take the left max characters.
If the position is smaller than my max value, I take the left position characters, subtract that from the max, then take the remaining right characters.
You only need to do this if you will have more than one possible limiter.