Q:

Android AlertDialog.Builder OnClickListener on custom button

I would like to display my omn Alert Dialog. I created the layout and then used it on a OnClickListener. (when you click on an element of a list, it displays details about it)
When the AlertDialog appears, all is fine but I would like that my own Dismiss button works. Sadly it doesn't and I don't know how to manage this. 
This is my XML file : 
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/DetailDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/popup_background" >

<Button
    android:id="@+id/dismissAlert"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/firstDivider"
    android:layout_centerHorizontal="true"
    android:background="@color/popup_background"
    android:text="Dismiss"
    android:textColor="@color/splashColor" />

<TextView
    android:id="@+id/alertDetail"
    android:layout_width="wrap_content"
    android:layout_height="80dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:paddingTop="20dp"
    android:text="Description : alert&apos;s details"
    android:textColor="@color/text"
    android:textSize="20dp" />

<View
    android:id="@+id/firstDivider"
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/alertDetail"
    android:background="@color/design_alert" />

And a part of my code
view.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {

                           this.messageDialog("Order " + string + " is waiting for a time estimate", OrderAlertsPage.this);     

                        }

                        public void messageDialog(String message, final Context activity) {
                            //On instancie notre layout en tant que View
                            LayoutInflater factory = LayoutInflater.from(activity);
                            final View alertDialogView = factory.inflate(R.layout.alert_detail_dialog, null);

                            //Création de l'AlertDialog
                            final AlertDialog.Builder adb = new AlertDialog.Builder(activity);
                            adb.setView(alertDialogView);

                            TextView text = (TextView) alertDialogView.findViewById(R.id.alertDetail);
                            text.setMovementMethod(ScrollingMovementMethod.getInstance());
                            text.setText(message);
                            text.setGravity(Gravity.CENTER);

                            Button dismiss = (Button) alertDialogView.findViewById(R.id.dismissAlert);
                            dismiss.setOnClickListener(new OnClickListener() {
                                public void onClick(View v) {

                                ((DialogInterface) adb).dismiss(); // I can't do it..

                                }
                            });

                            adb.show();

                        }
                    });

Thanks for your help

A:

Call dismiss() on the dialog, not the builder.
For example,
final AlertDialog dlg = adb.show();

// in onClick()
dlg.dismiss();

