I have custom DialogPreference
of two EditText
views and do comparison of those in onDialogClosed()
which doesn't work for me because in case strings
are not equal I can not stop dialog
closure, so I need the meth开发者_开发技巧od before onDialogClosed()
to make these comparisons and then decide whether to call onDialogClosed()
or not.
So, any other good place to make comparisons or ability to cancel dialog closure?
You can set the TextWatcher
implementation to the edittext and in its afterTextChanged()
callback do the comparison of strings. If the strings match enable the OK
button, else disable it.
ed2.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
if (ed1.gettext().tostring().compareIgnoreCase(s.tostring()) == 0) {
// enable the ok button.
} else {
// disable it.
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
I use onDismiss(DialogInterface dialog) to achieve something similar to this.
精彩评论