Possible Duplicate:
Dismiss a custom dialog?
I have a customized dialog, the layout file of the dialog contains a button with id “submit_btn“.
In java code, I setOnClickListener to the submit_btn button of the dialog:
View view = layoutInflater.inflate(R.layout.info_dialog, null);
AlertDialog infoDialog = new AlertDialog.Builder(MyActivity.this)
.setView(view)
.create();
infoDialog.show();
Button submitBtn = (Button) view.findViewById(R.id.submit_btn);
submitBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//ERROR: Cannot refer to a non-final variable infoDialog inside an inner class defined in a different method
infoDialog.dismiss();
}
});
Then, when I call infoDialog.dismiss();, Eclipse raise the error which complains that Cannot refer to a non-final variable infoDialog inside an inner class defined in a different method. How to get rid of this problem based on my code?
Could you just do this…
Or you could increase the scope of the infoDialog.