I tried the solution of PowerAktar, but the AlertDialog and the Builder always kept seperate parts. So how to get the "true" AlertDialog?
I found my solutions in the show-Dialog: You write
ad.show();
to display the dialog. In the help of show it says "Creates a AlertDialog with the arguments supplied to this builder and Dialog.show()'s the dialog." So the dialog is finally created here. The result of the show()-Command is the AlertDialog itself. So you can use this result:
AlertDialog adTrueDialog;
adTrueDialog = ad.show();
With this adTrueDialog it is possible to cancel() ...
adTrueDialog.cancel()
or to execute a buttons command within the dialog:
Button buttonPositive = adTrueDialog.getButton(Dialog.BUTTON_POSITIVE);
buttonPositive.performClick();