我想检查EditText的值是否大于5,我希望编辑文本的背景变为红色,但当我删除文本时,它就会停止。请帮帮忙。
vibration.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
vibration.setBackgroundColor(Color.YELLOW);
}
@Override
public void afterTextChanged(Editable s) {
float numV = Float.parseFloat(vibration.getText().toString());
if(numV > 5){
vibration.setBackgroundColor(Color.RED);
}else{
return;
}
}
});发布于 2021-12-23 11:06:39
首先检查从EditText获得的值是否为null。
if(!yourEditText.isempty)
{
//Do your work here
}
else{
//EditText is null}https://stackoverflow.com/questions/70460752
复制相似问题