In Android Studio, I want to check a radio button according to a text fetched from a table. Like, check 'MALE' if it's MALE in table or 'FEMALE' for FEMALE. Is it possible? If possible, how can I do it? Thanks in advance.
Asked
Active
Viewed 1,280 times
1 Answers
4
You may have a view like this:
<RadioGroup android:id="@+id/gender"
android:layout_width="match_parent"
android:orientation="horizontal"
android:checkedButton="@+id/block_scenario_off"
android:layout_height="wrap_content">
<RadioButton
android:layout_width="0dip"
android:layout_weight="1"
android:text="@string/male"
android:layout_height="wrap_content"
android:id="@+id/male"
android:layout_gravity="center|left"
android:onClick="@string/on_click"/>
<RadioButton
android:layout_width="0dip"
android:layout_weight="1"
android:text="@string/female"
android:onClick="@string/on_click"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/female"/>
</RadioGroup>
Now on the function write like this:
rgOption = (RadioGroup) findViewById(R.id.gender);
String mGender = // get text whether it is male or female
if(mGender.equals("Male"))
rgOption.check(R.id.male);
else
rgOption.check(R.id.female);

Riad
- 3,822
- 5
- 28
- 39
-
i think you can find here: http://stackoverflow.com/questions/11072576/set-selected-item-of-spinner-programmatically – Riad Aug 06 '16 at 17:14