【发布时间】:2016-12-10 06:23:26
【问题描述】:
在 Android Studio 中,我想根据从表格中获取的文本检查单选按钮。就像,如果它是表中的 MALE,请检查“MALE”或 FEMALE 的“FEMALE”。可能吗?如果可能的话,我该怎么做? 提前致谢。
【问题讨论】:
标签: android android-studio radio-button
在 Android Studio 中,我想根据从表格中获取的文本检查单选按钮。就像,如果它是表中的 MALE,请检查“MALE”或 FEMALE 的“FEMALE”。可能吗?如果可能的话,我该怎么做? 提前致谢。
【问题讨论】:
标签: android android-studio radio-button
你可能有这样的看法:
<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>
现在在函数上这样写:
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);
【讨论】: