Disable Button when Edit Text Fields empty

后端 未结 7 512
栀梦
栀梦 2020-12-31 04:22

I have two text fields and a Button. I want to disable the Button unless both EditText-Fields are not empty. I tried many solutions here at stackoverflow, but they don\'t wo

相关标签:
7条回答
  • 2020-12-31 05:06

    You method checkFieldsForEmptyValues is too complicated for what your doing, try just by doing :

     private  void checkFieldsForEmptyValues(){
            Button b = (Button) findViewById(R.id.btnRegister);
    
            String s1 = editText1.getText().toString();
            String s2 = editText2.getText().toString();
    
            if (s1.length() > 0 && s2.length() > 0) {
                b.setEnabled(true);
            } else {
                b.setEnabled(false);
            }
    
    }
    
    0 讨论(0)
提交回复
热议问题