I have this simple code:
AlertDialog dialog = new AlertDialog.Builder(this).create();
dialog.setTitle ("Alert title");
dialog.setMessage ("This is an alert");
dialog.show();
The dialog is shown but my Activity receives no callbacks. No onPrepareDialog, nothing.
Can I somehow hook AlertDialog without implementing a custom class extending AlertDialog?
Thanks.
onPrepareDialogis only called for dialogs managed by an Activity (i.e. dialogs created and returned withActivity.onCreateDialog(int)and shown viaActivity.showDialog(int)). Since you are creating and showing a dialog directly, these methods will not be called.See Creating Dialogs for more information on managed dialogs.
To respond to use input – like button clicks – you’ll want to use the builder methods as demonstrated by alezhka’s answer.