我只想将字符限制为 0-9、a-z、A-Z 和空格键.设置 inputtype 我可以限制为数字,但我无法弄清楚 Inputfilter 浏览文档的方式.
I want to restrict the chars to 0-9, a-z, A-Z and spacebar only. Setting inputtype I can limit to digits but I cannot figure out the ways of Inputfilter looking through the docs.
我在另一个论坛上找到了这个.像冠军一样工作.
I found this on another forum. Works like a champ.
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.isLetterOrDigit(source.charAt(i))) {
return "";
}
}
return null;
}
};
edit.setFilters(new InputFilter[] { filter });
这篇关于如何在 Android 中使用 InputFilter 限制 EditText 中的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!