ニューラルボタンを使うだけ
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(super.mContext);
dialogBuilder.setTitle(
super.mContext.getResources().getString(R.string.FAVORITE_RENAME_DIALOG_TITLE));
dialogBuilder.setMessage(
super.mContext.getResources().getString(R.string.FAVORITE_RENAME_DIALOG_MESSAGE));
final EditText input = new EditText(super.mContext);
input.setInputType(
InputType.TYPE_TEXT_FLAG_CAP_WORDS | InputType.TYPE_TEXT_VARIATION_LONG_MESSAGE);
input.setText(name);
input.setSelectAllOnFocus(true);
input.setHint(super.mContext.getResources().getString(R.string.FAVORITE_DIALOG_HINT));
input.setFilters(
new InputFilter[]{new DialogInputFilter(), new InputFilter.LengthFilter(20)});
dialogBuilder.setView(input);
dialogBuilder.setNeutralButton(
super.mContext.getResources().getString(R.string.FAVORITE_RENAME_DIALOG_POSITIVE),
new UpdateFavoriteListNameOnClickListener(name, favListId, input,
(Activity) super.mContext, this)
);
dialogBuilder.setNegativeButton(
super.mContext.getResources().getString(R.string.FAVORITE_DIALOG_NEGATIVE),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
}
}
);
ここで Create() 最初に alertDialog を取得し、 Button を取得して、必要なことを行います... im MinLength Validation にそれを使用する
dialogBuilder.create();
final AlertDialog alertDialog = dialogBuilder.show();
Button button = ((AlertDialog)alertDialog).getButton(AlertDialog.BUTTON_NEUTRAL);
input.addTextChangedListener(new TextMinLengthValidator(input, button) {
@Override
public void validate(EditText input, Button button) {
if (input.getText().length() < ConfigurationProvider.getConfig().getMinFavoriteNameLength() && button != null) {
button.setEnabled(false);
input.setError(mContext.getResources().getString(R.string.FAVORITE_DIALOG_LENGTH_NEGATIVE));
} else if(button != null) {
button.setEnabled(true);
input.setError(null);
}
}
});