为 android 创建自定义输入类型
我的要求是,用户应该只能输入数字 0 到 9 ,并且每 4 个字符之后,会自动在 edittext 中附加一个“-”符号。用户不应该能够删除 edittext 的任何部分除了最后。请建议锄头这样做。
用户不应该能够将光标移动到键入文本中间的任何位置,并且能够删除它。如何做到这一点?当用户移动光标位置时会调用什么事件?
my requirement is that, the user should only be able to type in digits 0 throu 9 , and that after every 4 characters, a "-" sign is automatically appended to the edittext.user should not be able to delete any part of the edittext except at end. Please suggest hoe to do this.
The user should not be able to move the cursor to anywhere in the middle of the typed text, and be able to delete it. How to accomplish this? What event is called when the user moves the position of the cursor?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的第一个要求是 0-9 仅通过在 XML 用户类型数字中设置编辑文本属性来满足
并计算编辑文本中的文本,在编辑文本对象中设置文本观察器侦听器并计算单词,您可以在其中附加“-”字符。
your first requirement is 0-9 is fulfill by set edit text property in XML user type number only
and to count your text in edit-text set text watcher listener in edit text object and count word and there you can append "-" character.
我找到了解决问题的方法:用户不应将光标移动到键入文本中间的任何位置。我们需要扩展
EditText
并添加覆盖以下函数:I found a solution to my problem : user should not be able to move the cursor to anywhere in the middle of the typed text. We need to extend
EditText
and add override the following function: