[英]EditText text formatting for forms
I'm looking for a simple way for Android, when a user taps a in a edit text box, it will add a hyphen inbetween the number set. 我正在寻找一种用于Android的简单方法,当用户在编辑文本框中点击时,它将在数字集之间添加一个连字符。 Sort of like a phone number, but will be set in a custom position.
有点像电话号码,但是会设置在自定义位置。
For example Book number 05, CD number 15, track number5 = 0515-5. 例如,书号05,CD号15,曲目号5 = 0515-5。 So when they start typing, the app will automatically enter the hyphen.
因此,当他们开始输入文字时,应用程序会自动输入连字符。
Should I use some type of listener and count how many characters are entered, then when it hits that number of characters, it will add the hyphen? 我应该使用某种类型的侦听器并计算输入了多少个字符,然后当碰到该数目的字符时,会添加连字符吗?
Thanks! 谢谢!
Use an InputFilter . 使用InputFilter 。
See my answers here: press "." 在这里查看我的答案: 按“。” many times (validate ip address in EditText while typing) and here: How to set Edittext view allow only two numeric values and two decimal values like ##.## for ideas on how to implement it
很多次(在键入时验证EditText中的IP地址)和此处: 如何设置Edittext视图仅允许两个数字值和两个十进制值(如##。##),以获取有关如何实现它的想法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.