title: Set value to the radio button in the radio group in Android
body: <p>I am building an app where I have radio group with three radio buttons. What I want is when I check the radio button I need to get the value of that radio button and save it in the realm database.
  And after that I want to get that radio button value from the Realm database and assign that value  to another radio button. </p>
  
  <p>For example: if I select radio button of radio group1 then I need to set that value to the radio button in the group2.</p>
  
  <p>Here is an example:</p>
  
  <p>activity_main.xml</p>
  
  <pre><code>        &lt;RadioGroup
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal"
              android:id="@+id/RadioGroup1"&gt;
  
              &lt;RadioButton
                  android:text="On Time"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:checked="true"
                  android:layout_alignParentTop="true"
                  android:id="@+id/fontimeRadio" /&gt;
  
              &lt;RadioButton
                  android:text="Delay"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignParentTop="true"
                  android:id="@+id/fdelayRadio" /&gt;
  
              &lt;RadioButton
                  android:text="Not"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignParentTop="true"
                  android:id="@+id/fnotRadio" /&gt;
  
  
          &lt;/RadioGroup&gt;
  
            &lt;RadioGroup
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal"
              android:id="@+id/RadioGroup2"&gt;
  
              &lt;RadioButton
                  android:text="On Time"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:checked="true"
                  android:layout_alignParentTop="true"
                  android:id="@+id/fontimeRadio1" /&gt;
  
              &lt;RadioButton
                  android:text="Delay"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignParentTop="true"
                  android:id="@+id/fdelayRadio1" /&gt;
  
              &lt;RadioButton
                  android:text="Not"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignParentTop="true"
                  android:id="@+id/fnotRadio1" /&gt;
  
  
          &lt;/RadioGroup&gt;
  </code></pre>
  
  <p>Model.java</p>
  
  <pre><code>   public class Model extends RealmObject{
      @PrimaryKey
  private int id;
  private boolean radiocheck;
  public int getId() {
      return id;
  }
  public void setId(int id) {
      this.id = id;
  }
  public boolean getRadioCheck() {
      return radiocheck;
  }
  public void setRadioCheck(boolean radiocheck) {
      this.radiocheck= radiocheck;
  }
  }
  </code></pre>
  
  <p>MainActivity.java</p>
  
  <pre><code>        RadioGroup radiocheck1= (RadioGroup)findViewById(R.id.RadioGroup1);
          RadioGroup radiocheck2= (RadioGroup)findViewById(R.id.RadioGroup2);
  </code></pre>
  
  <p>Now please tell me how to get the value from the selected radio button and save it in the Realm database and retrieve that value to set into the another radio button.</p>
  
  <p>For example we use </p>
  
  <pre><code>textview.setText(model.getName());
  </code></pre>
  
  <p>to set the text from the database but how to do that for radio buttons based on the above <code>Model.java</code> class as I have used the boolean function for radio button declaration.</p>