安卓:仅用于非数字字符输入类型 [英] Android: input type for only non-numeric chars
本文介绍了安卓:仅用于非数字字符输入类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好 我有一个EditText上,我想,让用户只输入非数字字符(比如AZ或az):有没有办法做到这一点?所有我所用的组合(文字,textPersonName的等等),让用户还可以选择号码。
Hello i have an EditText on which i would like to let user enter only non-numeric chars (say A-Z or a-z): is there a way to do it? All the combinations i used (text,textPersonName an so on) let the user select also numbers.
在此先感谢 ℃。
推荐答案
我认为你必须写自己的输入过滤器,并将其添加到组过滤器的的EditText。这样的事情可能工作:
I think you have to write your own InputFilter and add it to the set of filters for the EditText. Something like this might work:
InputFilter filter = new InputFilter() {
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend)
{
for (int i = start; i < end; i++) {
if (!Character.isLetter(source.charAt(i))) {
return "";
}
}
return null;
}
};
edit.setFilters(new InputFilter[]{filter});
这篇关于安卓:仅用于非数字字符输入类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文