Enable/Disable dialog buttons android
I have a dialogs which have one "Text Box" and Two buttons "Continue and Cancel". Conti开发者_JAVA百科nue button should be disable if we have empty text box and enabled otherwise.
basically you need textchange listener like this
etext.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(s.toString().equals("")
buttonContinue.setEnabled(false);
else
buttonContinue.setEnabled(true);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
Inflate a layout and set it as the view for the dialog or alert dialog. Between inflating the view and setting it as the dialog view, you can set an ontextchangetedlistener.
精彩评论