Reputation: 11
I'm using a RadioGroup
in my layout.
When I run the program, I'm getting the first RadioButton already selected out of 4 RadioButtons.
I want none of these RadioButtons initially selected.
Upvotes: 0
Views: 108
Reputation: 69689
If you want to set non of your RadioButton
to selected by default than use
android:checked="false"
in your RadioButton
SAMPLE CODE
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/choiceOne"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false"
android:text="choiceOne" />
<RadioButton
android:id="@+id/choiceTwo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false"
android:text="choiceTwo" />
<RadioButton
android:id="@+id/choiceThree"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false"
android:text="choiceThree" />
<RadioButton
android:id="@+id/choiceFour"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false"
android:text="choiceFour" />
</RadioGroup>
EDIT
if you want to set default radio button to selected than there is two way
You can use android:checked="true"
in particular RadioButton
You can use android:checkedButton="@+id/choiceOne"
in your RadioGroup
The id of the child radio button that should be checked by default within this radio group.
SAMPLE CODE FOR OPTION TWO
<RadioGroup
android:layout_width="match_parent"
android:checkedButton="@+id/choiceOne"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/choiceOne"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="choiceOne" />
<RadioButton
android:id="@+id/choiceTwo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="choiceTwo" />
<RadioButton
android:id="@+id/choiceThree"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="choiceThree" />
<RadioButton
android:id="@+id/choiceFour"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="choiceFour" />
</RadioGroup>
Upvotes: 4