首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当我从EditText中删除所有内容时,为什么我的应用程序会停止呢?

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

Stack Overflow用户
提问于 2021-12-23 10:23:29
回答 1查看 33关注 0票数 0

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

代码语言:javascript
复制
  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;
            }
        }
    });
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-12-23 11:06:39

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

代码语言:javascript
复制
if(!yourEditText.isempty)
{
//Do your work here
}
else{
//EditText is null}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70460752

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档