title: Populate a RadioGroup with RadioButtons from a string-array
body: <p>I have a layout that includes an empty <code>RadioGroup</code>. (I think this is the difference between this question and others that have been asked - I already have the empty RadioGroup in the correct place in my layout)</p>
  
  <p>I'd like to populate this <code>RadioGroup</code> with the <code>item</code>s from a <code>string-array</code> that I have defined in <code>strings.xml</code>.</p>
  
  <p>The array in <code>strings.xml</code> looks like this:</p>
  
  <pre><code>&lt;string-array name="currency_symbols"&gt;
      &lt;item&gt;$ - Dollar&lt;/item&gt;
      &lt;item&gt;€ - Euro&lt;/item&gt;
      &lt;item&gt;£ - Pound&lt;/item&gt;
      &lt;item&gt;¥ - Yen&lt;/item&gt;
      &lt;item&gt;# - Other&lt;/item&gt;
  &lt;/string-array&gt;
  </code></pre>
  
  <p>I am then trying to create a <code>RadioButton</code> and add it to the RagioGroup with teh following:</p>
  
  <pre><code>RadioGroup currencySettingRadioGroup = (RadioGroup) settings_dialog.findViewById(R.id.rg_currency_symbol);
  currencySettingRadioGroup.removeAllViews();
  
  RadioButton rb = new RadioButton(this);
  String[] currency_symbols_options_array = getResources().getStringArray(R.array.currency_symbols);
  for ( String this_currency_option: currency_symbols_options_array ) {
      rb.setText(this_currency_option);
      currencySettingRadioGroup.addView(rb);
  }
  </code></pre>
  
  <p>The <code>currencySettingRadioGroup.removeAllViews();</code> was added because I'm getting the following error, but it makes no difference:</p>
  
  <pre><code>java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
  </code></pre>
  
  <p>The line that is apparently causing the problem is the <code>currencySettingRadioGroup.addView(rb);</code> line...</p>
  
  <p>How do I do this properly?</p>
  
  <p>(I've looked at <a href="https://stackoverflow.com/questions/27836405/create-radiobutton-dynamically-with-string-array">Create RadioButton Dynamically with String Array</a> and the referenced <a href="http://android.okhelp.cz/create-radiobutton-radiogroup-dynamically-android-sample/" rel="nofollow noreferrer">http://android.okhelp.cz/create-radiobutton-radiogroup-dynamically-android-sample/</a> but can't seem to get anything to work)</p>