您的位置:首页 > 其它

MaterialEditText 一个灰常漂亮的强大EditText

2016-08-03 17:11 357 查看
非常强大 贴网址使用自己看吧

点击打开链接

下午用setOnKeyListener 监听按键输入,发现字母跟数字无法监听,估计这些都不是key吧。。。

于是乎转用TextWatcher 药到病除上代码:

//--新增 设置 EditText 范围检查
public ViewHolder setEditTextCheck(int viewID, Object object) {
final MaterialEditText editText = getView(viewID);
DeviceParameterBean deviceParameterBean = (DeviceParameterBean) object;
;
final int[] scope = deviceParameterBean.getScope();
if (deviceParameterBean != null) {
editText.setText(deviceParameterBean.getValue());
editText.setFloatingLabelText(deviceParameterBean.getName());
if (scope != null && scope.length == 2)
editText.setHelperText(String.format("请输入范围在[%s,%s]", scope[0], scope[1]));
}
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override
public void afterTextChanged(Editable editable) {
try {
float tempValue = Float.parseFloat(editText.getText().toString());
if (scope != null && scope.length == 2) {
if (tempValue > scope[1] || tempValue < scope[0]) {
editText.setError(String.format("非法输入\n请输入范围在[%s,%s]", scope[0], scope[1]));
}
}
} catch (Exception e) {
if (scope != null && scope.length == 2)
editText.setError(String.format("非法输入\n请输入范围在[%s,%s]", scope[0], scope[1]));
}
}
});
return this;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐