Android 使用RadioGroup和RadioButton实现单选效果
2016-04-17 22:02
621 查看
RadioButton和CheckBox的区别:CheckBox选中之后可以直接取消,RadioButton选中之后不能直接取消,所以一般情况下不建议单独使用。
1.RadioGroup:
RadioButton的一个集合,提供多选一机制。
2.属性:
android:orientation ("vertical"--垂直排布;"horizontal"--水平排布)
决定当前RadioGroup中RadioButton以什么形式排列
使用RadioButton和RadioGroup实现多选一效果
监听可以使用RadioGroup的OnClickeListener,也可以使用RadioButton的OnCliekedChangeListener。
样例程序包含一个包含两个RadioButton的RadioGroup和一个TextView,TextView会实时显示选中的性别信息。
activity_mail.xml
效果:
1.RadioGroup:
RadioButton的一个集合,提供多选一机制。
2.属性:
android:orientation ("vertical"--垂直排布;"horizontal"--水平排布)
决定当前RadioGroup中RadioButton以什么形式排列
使用RadioButton和RadioGroup实现多选一效果
监听可以使用RadioGroup的OnClickeListener,也可以使用RadioButton的OnCliekedChangeListener。
样例程序包含一个包含两个RadioButton的RadioGroup和一个TextView,TextView会实时显示选中的性别信息。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:android1="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <RadioGroup android:orientation="vertical" android1:id="@+id/radioGroup1" android1:layout_width="wrap_content" android1:layout_height="wrap_content" > <RadioButton android1:id="@+id/radio0" android1:layout_width="wrap_content" android1:layout_height="wrap_content" android1:checked="true" android1:text="男" /> <RadioButton android1:id="@+id/radio1" android1:layout_width="wrap_content" android1:layout_height="wrap_content" android1:text="女" /> </RadioGroup> <TextView android1:id="@+id/textView1" android1:layout_width="wrap_content" android1:layout_height="wrap_content" android1:text="选中:男" /> </LinearLayout>
activity_mail.xml
效果:
相关文章推荐
- Android init进程之解析及运行init.rc文件`
- 见证Android消息推送时刻--笔记---Socket即时通讯机制
- Android学习(27) -- 数据存储之SQLite数据库的增删改查
- Android View框架的draw机制
- Android位置服务--BaiduMap的使用(2)
- Android之sharepreference总结
- Android事件分发机制完全解析,带你从源码的角度彻底理解(下)
- csdn博客粘贴代码的方法+android 资源id转uri
- Android事件分发机制完全解析,带你从源码的角度彻底理解(上)
- 学习笔记(二)Activity
- Android SlidingMenu 使用详解
- Android学习(26) -- 数据存储之SQLite数据库的创建
- android错误之Unable to resolve target 'Google Inc.:Google APIs:6'
- android jni 开发入门
- android 动画
- NDK开发历程(一):android native code的调试方法
- Dom4j的应用 xml的使用 android
- 简单实现Activity退出时向下滑动退出的效果
- android studio 快捷键
- Android布局优化一之设计篇