您的位置:首页 > 移动开发 > Android开发

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

2012-01-30 20:56 447 查看
// 设置输入 的最大 长度
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();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android class
相关文章推荐