我想使用输入过滤器,我可以阻止第一个空格输入和编辑文本的最大长度限制为200个字符。
到目前为止我有这个: 我将maxlength放入同一个过滤器
private void setInputFilterForEmailAndPwd(final EditText amountEditText) {
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.isSpace(source.charAt(i))) {
return "";
}
}
return null;
}
};
amountEditText.setFilters(new InputFilter[] { filter });
}
setInputFilterForEmailAndPwd(emailEdit);
&#13;
答案 0 :(得分:1)
我找到了解决方案 我把新的输入过滤器,而不是setInputFilterForEmailAndPwd:
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.isWhitespace(source.charAt(i))) {
return "";
}
}
return null;
}
};
&#13;
然后:
emailEdit.setFilters(new InputFilter[] { filter, new InputFilter.LengthFilter(200) });
&#13;