简体   繁体   English

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

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

I want to check if the value of EditText is greater than 5, I want the background of the edittext to become RED and it does so but stops when I delete the Text.我想检查 EditText 的值是否大于 5,我希望 edittext 的背景变为红色,但它会在我删除文本时停止。 Please help.请帮忙。

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

first check if the the value you are getting from EditText is not null.首先检查您从 EditText 获得的值是否不是 null。

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

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

相关问题 当我从 EditText 中删除所有内容时,为什么应用程序会崩溃? - Why is the app crashing when I delete all from the EditText? 为什么我的应用程序在我将字符串(来自 EditText)解析为 Float 时崩溃 - Why my app crashes when I parse string (from EditText) to Float 当我将其移动到后台时,为什么我的Android应用程序停止? - Why does my Android app stops, when I move it to the background? 当我按下应用程序中的按钮时,所有editText和TextViews都会移至屏幕的左侧 - When I push a button in my app, all of the editText and TextViews move to the left side of the Screen 当变量具有空值时,我的应用程序停止。 为什么? - My app stops when a variable has null value. why? 为什么我按下按钮后我的应用程序停止运行 - Why does My app stops after i press the button 重构时为什么IntelliJ会删除我的文件? 所以我丢了我所有的工作 - Why does IntelliJ delete my files when I do refactor? So I lost all my work 当EditText为空并且按下按钮时,我的应用程序崩溃 - My app crashes when an EditText is empty and I press a button 为什么当我单击键盘上的“确定”按钮时清除了我的EditText? - Why my EditText is cleared when I click on “OK” button on the keyboard? 当我在 SearchView 中搜索任何位置时,我的应用会停止 - My app stops when I search any location in SearchView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM