The answer to Siavash is correct:
((RadioButton)radioGroup.getChildAt(index)).setChecked(true);
But keep in mind that a radioGroup may contain views other than radioButtons - like this example, which includes a small line under each selection.
<RadioGroup android:id="@+id/radioKb" android:layout_width="wrap_content" android:layout_height="wrap_content" > <RadioButton android:id="@+id/kb1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:button="@null" android:drawableRight="@android:drawable/btn_radio" android:text="Onscreen - ABC" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:background="#33000000" /> <RadioButton android:id="@+id/kb2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:button="@null" android:drawableRight="@android:drawable/btn_radio" android:text="Onscreen - Qwerty" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:background="#33000000" /> <RadioButton android:id="@+id/kb3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:button="@null" android:drawableRight="@android:drawable/btn_radio" android:text="Standard softkey" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:background="#33000000" /> <RadioButton android:id="@+id/kb4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:button="@null" android:drawableRight="@android:drawable/btn_radio" android:text="Physical keyboard" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:background="#33000000" /> </RadioGroup>
In this case, using index 1, for example, will result in an error. The entry in index 1 is the first dividing line, not the radio beater. The radio bytes in this example are at indices 0, 2, 4, 6.
Alan Jul 19 '16 at 2:53 on 2016-07-19 02:53
source share