title: Android: How to check/uncheck a RadioButton inside a RadioGroup programmatically in Java
body: <p>I have to activities, MainActivity and settingsActivity. Because of that I'm using the methods <code>onPause</code> and <code>onResume</code> in the settingsActivity. So that the things I have done in the settingsActivity are saved after switching to MainActivity and back again.</p>
  
  <p><strong>settingsActivity:</strong></p>
  
  <p>Here I have a <code>TextView</code> (called "settings2") as a kind of variable and my three <code>RadioButtons</code> (<code>radio0</code>, <code>radio1</code> and <code>radio2</code>) which are inside a <code>RadioGroup</code>. 
  After switching to the MainActivity my programe puts "0" in a file (which is saved on the sdcard) if <code>radio0</code> was last checked. But if <code>radio1</code> was last checked, it puts 1 in that file. And if <code>radio2</code> was last checked, it puts 2 in that file. 
  I used this in the method <code>onPause</code>.</p>
  
  <p>Then in the method <code>onResume</code> I read the text of that file and put it in the <code>TextView</code> "settings2".
  After this code (still in <code>onResume</code>) I want to check/uncheck my <code>RadioButtons</code>. So if the text of the <code>TextView</code> "settings2" is "0" the <code>RadioButton</code> <code>"radio0"</code> shall be checked and the others not. If the text of this <code>TextView</code> is "1" the <code>RadioButton</code> <code>"radio1"</code> shall be checked and the others not. And if the text of this <code>TextView</code> is "2" the <code>RadioButton</code> <code>"radio2"</code> shall be checked and the others not.
  To do this I used the following two codes but unfortunately they didn't work.</p>
  
  <p>First code:</p>
  
  <pre><code>if (settings2.getText().equals("0")) {
  
          radio0.setChecked(true);
          radio1.setChecked(false);
          radio2.setChecked(false);
  
      } else if (settings2.getText().equals("1")) {
  
          radio0.setChecked(false);
          radio1.setChecked(true);
          radio2.setChecked(false);
  
      } else if (settings2.getText().equals("2")) {
  
          radio0.setChecked(false);
          radio1.setChecked(false);
          radio2.setChecked(true);
  
      } 
  </code></pre>
  
  <p>Second code:</p>
  
  <pre><code>if (settings2.getText().equals("0")) {
  
          radioGroup1.check(R.id.radio0);
  
      } else if (settings2.getText().equals("1")) {
  
          radioGroup1.check(R.id.radio1);
  
      } else if (settings2.getText().equals("2")) {
  
          radioGroup1.check(R.id.radio2);
  
      } 
  </code></pre>
  
  <p>Can someone help with this little problem please? I'm looking forward to your help!</p>
  
  <p>Thanks in advance!</p>