I have a custom AlertDialog with radio buttons which will open on click of a textview. Everything is working as it is supposed to except that the radio buttons are never shown as "checked". Whenever I open the AlertDialog all of the buttons are unchecked. After selecting a button and opening the AlertDialog again the buttons are unchecked again.

My XML:

```
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"
          android:padding="15dp">

<RadioGroup
    android:id="@+id/rg_gender"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_marginRight="30dp"
    android:layout_marginLeft="30dp"
    android:layout_marginTop="10dp"
    android:orientation="vertical"
    android:layout_gravity="center_horizontal">

    <RadioButton
        android:id="@+id/buttonMale"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/therapist_male"
        />

    <RadioButton
        android:id="@+id/buttonFemale"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/therapist_female"
        />

    <RadioButton
        android:id="@+id/buttonEither"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/therapist_either"
        />
</RadioGroup>
</LinearLayout>

```

My AlertDialog:

```
private void therapistDialog() {

    final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View dialogView = inflater.inflate(R.layout.gender_dialog, null);
    dialogBuilder.setView(dialogView);
    dialogBuilder.setNegativeButton(getResources().getString(R.string.cancel_button), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    final AlertDialog alertDialog = dialogBuilder.show();

    final RadioGroup rg = (RadioGroup) dialogView.findViewById(R.id.rg_gender);
    rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (checkedId == R.id.buttonMale){
                tvGender.setText(getResources().getString(R.string.therapist_male));
                therapistSex = 0;
                mMassage.setTherapistSex(therapistSex);
                male.setChecked(true);
                alertDialog.dismiss();
            } else if (checkedId == R.id.buttonFemale){
                tvGender.setText(getResources().getString(R.string.therapist_female));
                therapistSex = 1;
                mMassage.setTherapistSex(therapistSex);
                alertDialog.dismiss();
            } else if (checkedId == R.id.buttonEither){
                tvGender.setText(getResources().getString(R.string.therapist_either));
                therapistSex = 2;
                mMassage.setTherapistSex(therapistSex);
                alertDialog.dismiss();
            }
        }
    });

```