TextView가 비어있는 경우 경고 대화 상자를 닫으려고합니다. 일부 게시물은 지나치지 만 커스터마이징 경고 대화 상자는 아닙니다. 이 문제를 해결하는 방법.경고 대화 상자의 editText가 비어있는 경우 경고 대화 상자 닫기를 비활성화하는 방법
currentPassword.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) {
if(TextUtils.isEmpty(currentPassword.getText().toString().trim())){
button.setEnabled(false);
alert.setCancelable(false);
} else{
button.setEnabled(true);
alert.setCancelable(true);
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
:
Button button = alert.getButton(alert.BUTTON_NEGATIVE);
button.setEnabled(false);
alert.setCancelable(false);
이 암호 글고 치기에 TextWhatcher 추가 : 미리 감사는 여기 비활성화로 설정 처음에 내 코드 샘플 사용자 정의 경고 대화 코드
protected void showInputDialog() {
// get prompts.xml view
LayoutInflater layoutInflater = LayoutInflater.from(Nav_Settings.this);
View promptView = layoutInflater.inflate(R.layout.nav_settings_change_password, null);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Nav_Settings.this);
alertDialogBuilder.setView(promptView);
alertDialogBuilder.setIcon(R.drawable.icon_secret);
alertDialogBuilder.setTitle("CHANGE PASSWORD");
final EditText currentPassword = (EditText) promptView.findViewById(R.id.etCurrentPassword);
final EditText newPassword = (EditText) promptView.findViewById(R.id.etNewPassword);
final EditText confirmNewPassword = (EditText) promptView.findViewById(R.id.etConfirmNewPassword);
// setup a dialog window
alertDialogBuilder.setPositiveButton("Update Password", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (TextUtils.isEmpty(currentPassword.getText().toString().trim())) {
currentPassword.setError("should not be empty");
} else if (TextUtils.isEmpty(newPassword.getText().toString().trim())) {
newPassword.setError("should not be empty");
} else if (TextUtils.isEmpty(confirmNewPassword.getText().toString().trim())) {
confirmNewPassword.setError("should not be empty");
} else if (newPassword.getText().toString().trim() != confirmNewPassword.getText().toString().trim()) {
confirmNewPassword.setError("new password not matching");
} else if (currentPassword == newPassword) {
newPassword.setError("new password should not be current password");
} else {
Toast.makeText(getApplicationContext(), currentPassword.getText().toString() + "\n" + newPassword.getText().toString() + "\n" + confirmNewPassword.getText().toString(), Toast.LENGTH_SHORT).show();
}
}
}).setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
// create an alert dialog
AlertDialog alert = alertDialogBuilder.create();
alert.show();
alert.getButton(alert.BUTTON_NEGATIVE).setTextColor(getResources().getColor(R.color.colorPrimary));
alert.getButton(alert.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.colorPrimary));
Typeface face = Typeface.createFromAsset(getAssets(),
"fonts/RobotoCondensed-Bold.ttf");
alert.getButton(alert.BUTTON_POSITIVE).setTypeface(face);
alert.getButton(alert.BUTTON_NEGATIVE).setTypeface(face);
}
당신이 [이] (HTTP 확인 않았다} 사실 수 있습니다 : // 유래합니다. com/questions/26086848/android-dont-dismiss-alertdialog-after-clicking-positivebutton) –
지금 내 대답을 확인하십시오. –
모두 감사합니다, 나는 @kishire Jethava 제안을 따라 나를 위해 일했다. – Andi