I have a dialog with a custom layout, and I try to close it when I press a button:
private void showAboutDialog() {
dialog = new Dialog(MainMenu.this);
dialog.setContentView(R.layout.about_dialog);
dialog.setCancelable(true);
dialog.setTitle(R.string.about_title);
dialog.show();
LayoutInflater inflater = (LayoutInflater)
getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.about_dialog,
(ViewGroup) findViewById(R.id.layout_root));
Button closeButton = (Button) layout.findViewById(R.id.about_close_button);
closeButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) {
dialog.dismiss();
}
});
}
But it doesn't work.