This may seem like a simple problem to solve, but I’m new to Android so please bear with me. I have the following code fragment that displays an alert box:
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();
Everything works. The problem is, I don’t have access to the “pwDialog” variable, so how do I close my dialog?
It looks as though you should have access to your pwDialog variable. You may need to declare it as final though.