können Sie haben eine Ansicht wie folgt aus:
<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>
nun auf die Funktion Schreib wie folgt aus:
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);
Was passiert, wenn ich das gleiche für Spinners tun wollen ??? –
ich denke, dass Sie hier finden können: http://stackoverflow.com/questions/11072576/set-selected-item-of-spinner-programmatically – Riad