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);
}
}
One easy way can also be to set
onKeyListener
to youreditText()
, then if there is something ineditText()
, set button enable if nothing disable it.You're correct about needing a TextWatcher. The
afterTextChanged(Editable)
method is the one you're interested in for something like this. Call yourbuttonEnable()
method from it, and add the TextWatcher to any applicable text fields. (Looks likefeedback
andemail
from your sample.)