@Override
protected void showDialog(Bundle state) {
super.showDialog(state);
EditText et = getEditText();
et.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
Dialog d = getDialog();
if (d instanceof AlertDialog) {
AlertDialog dialog = (AlertDialog) d;
Button positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
// Check if the EditText is empty
if (s.length() < mMinLength) {
// Disable OK button
positiveButton.setEnabled(false);
} else {
// Re-enable the button.
positiveButton.setEnabled(true);
}
}
}
});
}
showDialog
方法不在支持库中。
如何使用支持库来使用EditTextPreference
禁用按钮
以及如何使用添加更改侦听器?