繁体   English   中英

当我从 EditText 中删除所有内容时,为什么我的应用程序停止了?

[英]Why my app stops when I delete all from EditText?

我想检查 EditText 的值是否大于 5,我希望 edittext 的背景变为红色,但它会在我删除文本时停止。 请帮忙。

  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;
            }
        }
    });

首先检查您从 EditText 获得的值是否不是 null。

if(!yourEditText.isempty)
{
//Do your work here
}
else{
//EditText is null}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM