Android: How to enable my button if EditText is not empty?

I have 2 EditTexts; 01 and 02. My button will be disabled after starting the activity and when these two EditText contain text, the button should be turned on again. However, my button is always disabled and cannot enable it with button.setEnabled(true); .

Can anyone help me with this?

 summit.setEnabled(false); buttonEnable(); public void buttonEnable(){ if (feedback.length()>0 && email.length()>0){ summit.setEnabled(true); }else{ summit.setEnabled(false); } } 
+3
source share
2 answers

You are right to use TextWatcher. The afterTextChanged(Editable) method is the one that interests you for something similar. Call your buttonEnable() method and add a TextWatcher to any applicable text fields. (It looks like feedback and email from your sample.)

+3
source

One simple way could be to set onKeyListener to your editText() , and then if there is editText() in editText() , set the enable button if nothing is disabled.

0
source

All Articles