title: RadioGroup Inside Dialog Alert Crashes The App When .positive
body: <p>I have an alert dialog that has a Radiogroup of 5 buttons. When OK is pressed, the app crashes whether I chose a radio button or not. Itried different methods for Radiogroup but all fail. If someone can help me, I would be thankful.</p>
  
  <p>PS. I have a switch case that is calling this Alert Dialog Activity. colorpickdialog();</p>
  
  <p>This is my Alert Dialog XML:</p>
  
  <pre><code>&lt;RadioGroup
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/radiosizeg"
      android:layout_below="@+id/bgadddialogsize"
      android:layoutDirection="rtl"
      android:gravity="start"
      android:layout_gravity="start"
      android:layout_alignParentRight="true"
      android:layout_alignParentEnd="true"&gt;
  &lt;RadioButton
      android:text="@string/sizesmall"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/sizesmall"/&gt;
  
  &lt;RadioButton
      android:text="@string/sizemed"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/sizemed" /&gt;
  
      &lt;RadioButton
          android:text="@string/sizelar"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/sizelar" /&gt;
  
      &lt;RadioButton
          android:text="@string/sizefill"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/sizefill" /&gt;
  
      &lt;RadioButton
          android:text="@string/sizecustom"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/sizecustom" /&gt;
  &lt;/RadioGroup&gt;
  </code></pre>
  
  <p>and this is my MainActivity.class:</p>
  
  <pre><code>public void colorpickdialog() {
      // get prompts.xml view
      final RadioGroup radiosizeg = (RadioGroup) findViewById(R.id.radiosizeg);
      LayoutInflater layoutInflater2 = LayoutInflater.from(MainActivity.this);
      View promptView2 = layoutInflater2.inflate(R.layout.colorpickdialog, null);
      AlertDialog.Builder alertDialogBuilder2 = new AlertDialog.Builder(MainActivity.this);
      alertDialogBuilder2.setView(promptView2);
      // setup a dialog window
      alertDialogBuilder2.setCancelable(false)
              .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
  
                      radiosizeg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                          @Override
                          public void onCheckedChanged(RadioGroup radioGroup, int i) {
                              int id = radiosizeg.getCheckedRadioButtonId();
                              switch (id) {
                                  case R.id.sizesmall:
                                      Toast.makeText(getApplicationContext(),"A", Toast.LENGTH_SHORT).show();
                                      break;
                                  case R.id.sizemed:
                                      Toast.makeText(getApplicationContext(),"B", Toast.LENGTH_SHORT).show();
                                      break;
                                  case R.id.sizelar:
                                      Toast.makeText(getApplicationContext(),"C", Toast.LENGTH_SHORT).show();
                                      break;
                                  case R.id.sizefill:
                                      Toast.makeText(getApplicationContext(),"D", Toast.LENGTH_SHORT).show();
                                      break;
                                  case R.id.sizecustom:
                                      Toast.makeText(getApplicationContext(),"E", Toast.LENGTH_SHORT).show();
                                      break;
                                  default:
                                      onCheckedChanged(radioGroup, i);
                                      break;
                              }
                          }
                      });
                  }
              })
              .setNegativeButton(getString(R.string.cancel),
                      new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int id) {
                              dialog.cancel();
                          }
                      });
  </code></pre>
  
  <p>The error stacktrace</p>
  
  <pre><code>10-27 20:56:53.753 4312-4327/? E/ReportTools: This is not beta user build
  10-27 20:56:53.959 4312-7462/? E/HsmCoreServiceImpl: onTransact in code is: 102
  10-27 20:56:54.025 13521-13539/? E/HwLauncher: SettingsEx , no such field.
  10-27 20:56:54.088 8152-8242/? E/PackageLogInfoManager: checkPackageLogState, cr: android.app.ContextImpl$ApplicationContentResolver@4d74931, packageNames: null
  </code></pre>