2016-08-04 88 views
-1

在Android Studio中,我想根据从表格中提取的文本检查单选按钮。比如,勾选'MALE',如果它是表格中的男性或女性的'女性'。可能吗?如果可能,我该怎么做? 在此先感谢。根据文本检查单选按钮

回答

2

你可能有这样的观点:

<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); 
+0

如果我想要做的纱厂一样??? –

+0

我想你可以在这里找到:http://stackoverflow.com/questions/11072576/set-selected-item-of-spinner-programmatically – Riad