-1

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.

For example: if I select radio button of radio group1 then I need to set that value to the radio button in the group2.

Here is an example:

activity_main.xml

        <RadioGroup
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:id="@+id/RadioGroup1">

            <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" />

            <RadioButton
                android:text="Delay"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:id="@+id/fdelayRadio" />

            <RadioButton
                android:text="Not"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:id="@+id/fnotRadio" />


        </RadioGroup>

          <RadioGroup
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:id="@+id/RadioGroup2">

            <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" />

            <RadioButton
                android:text="Delay"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:id="@+id/fdelayRadio1" />

            <RadioButton
                android:text="Not"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:id="@+id/fnotRadio1" />


        </RadioGroup>

Model.java

   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;
}
}

MainActivity.java

        RadioGroup radiocheck1= (RadioGroup)findViewById(R.id.RadioGroup1);
        RadioGroup radiocheck2= (RadioGroup)findViewById(R.id.RadioGroup2);

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.

For example we use

textview.setText(model.getName());

to set the text from the database but how to do that for radio buttons based on the above Model.java class as I have used the boolean function for radio button declaration.

halfer
  • 19,824
  • 17
  • 99
  • 186
ahmed sharief
  • 83
  • 2
  • 13

1 Answers1

0

You can select radio group and set text to radio button using loop.

RadioGroup rbtnGrp = (RadioGroup) findViewById(R.id.RadioGroup1);

((RadioButton) rbtnGrp.getChildAt(2)).setText("your radio button data");
santosh kumar
  • 2,952
  • 1
  • 15
  • 27