I have an AlertDialog.Builder inside which a button is present and I want to dismiss the dialog when it is clicked.
But there are no .dismiss() or .cancel() methods.
LayoutInflater inf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inf.inflate(R.layout.map_window, null);
window = new AlertDialog.Builder(activity);
window.setCancelable(true);
buttonStar = (ImageButton)layout.findViewById(R.id.buttonStar);
buttonStar.setBackgroundResource(R.drawable.star);
buttonStar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
//finishing window;
}
});
window.setPositiveButton("Volver", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int wichButton) {
}
});
window.show();
}
AlertDialog.Builder#showreturns theAlertDialogitself, so just get the AlertDialog itself that returns fromshowand call dismiss on it: