Android 动态限制EditText输入的字条类型及键盘类型、对输入的监控

来源:互联网 发布:2016手机记账软件 编辑:程序博客网 时间:2024/05/03 23:34
// 设置输入 的最大 长度
InputFilter[] filters = new InputFilter[1];
filters[0] = new InputFilter.LengthFilter(8); //限制最大输入长度
etUnit.setFilters(filters);
// 只输入 数字
etUnit.setKeyListener(new NumberKeyListener() {
protected char[] getAcceptedChars() {
char[] numberChars = { '1', '2', '3', '4', '5', '6', '7', '8',
'9', '0' };
return numberChars;
}


public int getInputType() {
return 3;
}

});

etUnit.addTextChangedListener(new TextWatch());


// 监视配码输入框数字变化事件
class TextWatch implements TextWatcher {


public void afterTextChanged(Editable s) {


}


public void beforeTextChanged(CharSequence s, int start, int count,
int after) {


}


public void onTextChanged(CharSequence s, int start, int before,
int count) {
updateEditTexts();
}
}

原创粉丝点击