이것은 간단한 문제처럼 보일지 모르지만 저는 Android에 익숙하지 않으므로 저와 함께주십시오. 경고 상자를 표시하는 다음 코드 단편이 있습니다.AlertDialog 상자를 닫으십시오.
Builder pwBox = new AlertDialog.Builder(this);
AlertDialog pwDialog;
LayoutInflater mInflater = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View pwView = mInflater.inflate(R.layout.passworddialog, null);
Button btnSetPassword = (Button) pwView
.findViewById(R.id.btnSetPassword);
pwBox.setView(pwView);
pwBox.setCancelable(false);
pwBox.setTitle("New Password");
pwDialog = pwBox.create();
btnSetPassword.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//pwDialog.dismiss(); <------ Problem Line
}
});
pwDialog.show();
모든 것이 작동합니다. 문제는 "pwDialog"변수에 액세스 할 수 없기 때문에 대화 상자를 어떻게 닫을 수 있습니까? 당신이 당신의 pwDialog 변수에 액세스 할 수 있어야합니다 것처럼
private static final CommandWrapper DISMISS = new CommandWrapper(Command.NO_OP);
public static AlertDialog createDeletionDialog(final Context context,
final String message, final String positiveLabel, final Command positiveCommand) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setCancelable(true);
builder.setMessage(message);
builder.setInverseBackgroundForced(true);
builder.setPositiveButton(positiveLabel, new CommandWrapper(positiveCommand));
builder.setNeutralButton("Cancel", DISMISS);
return builder.create();
}
이것은 내 문제였습니다. 최종 키워드를 추가해야하는데 이제 작동합니다. 감사! – Icemanind