Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have 2 EditTexts; 01 and 02. My button will be disabled once the activity is started and when these two EditText contain text, the button has to be enabled again. However my button is always disabled and can't enable it using 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);
    }
}
like image 731
Michelle Chan Avatar asked Nov 21 '25 18:11

Michelle Chan


1 Answers

You're correct about needing a TextWatcher. The afterTextChanged(Editable) method is the one you're interested in for something like this. Call your buttonEnable() method from it, and add the TextWatcher to any applicable text fields. (Looks like feedback and email from your sample.)

like image 65
adamp Avatar answered Nov 23 '25 07:11

adamp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!