Android:扩展EditText的inputType?
我想允许 EditText 输入 0-9、“、”或“-”,但找不到答案。
我知道使用“|”作为分隔符是可能的:
android:inputType="number|text"
但是我怎样才能归档这样的东西(太糟糕了,它不起作用):
android:inputType="number|,|-"
有人知道吗?
问候,
科迪
添加以下评论:
私有类 MyKeylistener 扩展 NumberKeyListener {
public int getInputType() { 返回InputType.TYPE_CLASS_NUMBER; } @覆盖 受保护的 char[] getAcceptedChars() { 返回新的 char[] {'0','1','2','3','4','5','6','7','8','9',',', '-'}; }
}
I'd like to allow possible inputs of 0-9, "," or "-" for EditText and couldn't find an answer.
I know using the "|" as an separator is possible:
android:inputType="number|text"
But how can I archive something like this (too bad it doesn't work):
android:inputType="number|,|-"
Does anyone know?
Regards,
cody
Addition to the comment below:
private class MyKeylistener extends
NumberKeyListener {public int getInputType() { return InputType.TYPE_CLASS_NUMBER; } @Override protected char[] getAcceptedChars() { return new char[] {'0','1','2','3','4','5','6','7','8','9',',','-'}; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为没有办法提供这样的任意过滤器。您必须使用提供的过滤器类型。
如果您找不到满足您要求的这些类型的组合,您可能需要使用 TextWatcher 或 InputFilter在编辑文本上。
I don't think there is a way to provide an arbitrary filter like that. You have to use the provided filter types.
If you can't find a combination of those types that does what you want, you probably need to do the filtering yourself using a TextWatcher or InputFilter on the EditText.