I have been looking a lot for examples on how to correctly extend AlertDialogs and get the expected behaviour, but I can hardly find any.
The docs on google doesnt r
I've successfully made my own custom AlertDialog by extending the Builder class.
public class MyDialog extends AlertDialog.Builder {
    private Context mContext;
    private AlertDialog mAlertDialog;
    public MyDialog(Context context) {
        super(context);
        mContext = context;
    }
    @SuppressLint("InflateParams")
    @Override
    public AlertDialog show() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.my_dialog, null);
        ...
        mAlertDialog = super.show();
        return mAlertDialog;
    }
}
Then, from the code, I instantiate them like this:
MyDialog myDialog = new MyDialog(getActivity());
myDialog.show();
The only caveat is you have to take care of dismissing the dialog properly on orientation change or other events that don't explicit call the dismiss() method, like the back button or something else. Otherwise, you'll have memory leaks from that dialog.