单选按钮RadioButton
来源:互联网 发布:全金属开放式网络桥架 编辑:程序博客网 时间:2024/05/16 12:59
单选按钮RadioButton
<RadioButton android:id="@+id/radioButton_main" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="单选按钮" /> <RadioGroup android:id="@+id/radioGroup_main" android:layout_width="wrap_content" android:layout_height="wrap_content" > <RadioButton android:id="@+id/radio_man" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="男" /> <RadioButton android:id="@+id/radio_woman" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="女" /> </RadioGroup>
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 关联布局文件 setContentView(R.layout.activity_main); mRadioButton = (RadioButton) findViewById(R.id.radioButton_main); mRadioGroup = (RadioGroup) findViewById(R.id.radioGroup_main); // 设置单选按钮的监听事件 mRadioButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { Log.e("mRadioButton", "被选中了"); } } }); // 设置单选按钮组的监听事件 mRadioGroup.setOnCheckedChangeListener( new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.radio_man: Log.e("mRadioGroup", "选中男生"); break; case R.id.radio_woman: Log.e("mRadioGroup", "选中女生"); break; } // 改变第一个单选按钮的选中状态 mRadioButton.setChecked(false); } }); int id = mRadioGroup.getCheckedRadioButtonId(); Log.e("当前被选中的id为", "id = "+id); int childCount = mRadioGroup.getChildCount(); Log.e("选项总数", childCount+""); String totalName = ""; for (int i = 0; i < childCount; i++) { RadioButton rb = (RadioButton) mRadioGroup.getChildAt(i); totalName += rb.getText().toString(); } Log.e("选项有", totalName); }
“`
0 0
- RadioButton单选按钮
- RadioButton单选按钮
- RadioButton单选按钮
- RadioButton单选按钮
- 单选按钮RadioButton
- 单选按钮RadioButton
- RadioButton单选按钮
- 单选按钮RadioButton
- 自定义RadioButton ,单选按钮
- 单选按钮RadioButton&RadioGroup
- 单选按钮RadioButton使用
- RadioButton 单选按钮组
- iOS RadioButton 单选按钮
- RadioButton(单选按钮)
- 03 RadioButton 单选按钮
- Android RadioButton 单选按钮
- UltraWebGrid控件增加radiobutton单选按钮
- 单选按钮RadioGroup与RadioButton实例
- zynq 内核编译
- 欧几里德 java
- poj 3040 深入理解贪心思想
- 2
- 流水号/缺省值
- 单选按钮RadioButton
- 自定义控件-TableView,ScrollView嵌套Listview
- jquery的使用
- Resolved versions for app (18.0) and test app (19.0) differ.
- spring框架概述
- https iOS端需要做的事情
- 日志文件中中文乱码
- Codeforces Round #383 (Div. 2)C. Arpa's loud Owf and Mehrdad's evil plan(dfs&lcm)
- php缓冲区详解