关于如何在XML中设置RadioButton默认选中
2014-11-20 11:49
288 查看
首先我遇到的问题是:
当运行时候,社区永远是被选中的,不是我想要的结果。
解决方案:需要给RadioButton添加id属性,这样默认选中才会生效。如:
OK!问题解决了。
补充:后台如何获取选中的RadioButton:
<RadioGroup android:id="@+id/radioGroup" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="商圈" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="社区" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="大学" /> </RadioGroup>
当运行时候,社区永远是被选中的,不是我想要的结果。
解决方案:需要给RadioButton添加id属性,这样默认选中才会生效。如:
<RadioGroup android:id="@+id/propertyRadioGroup" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <RadioButton android:id="@+id/propertyRadioButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="商圈" /> <RadioButton android:id="@+id/propertyRadioButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="社区" /> <RadioButton android:id="@+id/propertyRadioButton3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="大学" /> </RadioGroup>
OK!问题解决了。
补充:后台如何获取选中的RadioButton:
int radioButtonId=propertyRadioGroup.getCheckedRadioButtonId(); RadioButton radioButton = (RadioButton)propertyRadioGroup.findViewById(radioButtonId); handler.sendToastMessage("text:"+radioButton.getText().toString()); handler.sendToastMessage("hint:"+radioButton.getHint().toString());
相关文章推荐
- MVC架构下,关于如何设置DropDownList的默认选中项以及修改后填充以后的设置选中项
- Android RadioGroup中设置默认选中RadioButton 后,选中两个的问题 解决方法
- 在MyEclipse中如何设置jsp,xml等文件默认的打开方式
- HTML中的<select>标签如何设置默认选中的选项
- jquery如何根据值设置默认的选中项
- Android RadioGroup中设置默认选中RadioButton 后,选中两个的问题 解决方法
- select标签如何设置默认选中的选项
- html中<checkbox>标签用法解析及如何设置checkbox复选框的默认选中状态
- Android 动态设置RadioButton选中和没选中的颜色及设置默认选中某一项
- HTML中的<select>标签如何设置默认选中的选项
- 关于如何给<input type="date">设置默认当前日期的方法 和 给table固定宽度
- HTML中的<select>标签如何设置默认选中的选项
- 关于sms center number 中心默认号码是如何设置的
- html中<radio>单选按钮控件标签用法解析及如何设置默认选中
- RadioButton设置默认选中后无法取消,可选中多个的问题
- jQuery MultiSelect 如何设置多选框的默认选中项
- Wpf Datagrid 设置了模板 checkbox 如何一次选中,单击就选中。默认是要双击才得
- RadioGroup动态添加RadioButton,RadioButton设置默认选中第一个,点击其他的RadioButton第一个不再选中,第一个不再选中
- 关于Spinner默认显示的文字布局属性与下拉显示的文字布局属性如何分别设置
- RadioGroup里设置RadioButton为初始的都不选中状态及设置默认选中出现的问题及解决方法