Android控件之RadioGroup与RadioButton(单选控件)
一、RadioGroup与RadioButton
1、什么是RadioGroup:
RadioButton的一个集合,提供多选机制
2、什么是RadioButton:
RadioButton包裹在RadioGroup中,RadioGroup表示一组RadioButton,下面可以有很多个RadioButton,但只能有一个被选中
3、RadioGroup属性:
android:orientation—— 设置RadioGroup中RadioButton以什么形式排列(有两个值分别是:horizontal(水平排布)和 vertical(垂直排布))
二、代码演示:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" > <RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" > <RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="男" /> <RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女" /> </RadioGroup> </LinearLayout>
package com.muke.textview_edittext; import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.app.Activity; public class MainActivity extends Activity implements OnCheckedChangeListener{ private RadioGroup rg; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //第一步:初始化控件(找到需要操作的控件)
rg = (RadioGroup) findViewById(R.id.radioGroup1); //第二步:实现RadioGroup的监听事件
rg.setOnCheckedChangeListener(this); } @Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
//checkedId表示被选中的那个RadioButton的id
switch(checkedId){
case R.id.radio0:
System.out.println("男被选中");
break;
case R.id.radio1:
System.out.println("女被选中");
break;
}
} }
Android控件之RadioGroup与RadioButton(单选控件)的更多相关文章
- RadioGroup和RadioButton(单选框)
1.布局文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t ...
- Android控件:RadioButton(单选button)
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...
- Android基本控件之RadioGroup
我们在手机上经常看到一堆选项,但是我们只能选择一个,那么在Android中,这个控件就叫做RadioButton,也就是单选按钮的意思,他们之所以能够达到只能选择一个的效果,是因为有一个RadioGr ...
- android应用开发--------------看RadioGroup源代码,写相似单选选项卡的集成控件(如底部导航,tab等等)
博客为 有时个哥 原创.如需转载请标明出处:http://blog.csdn.net/ls703/article/details/46694967 watermark/2/text/aHR0cDovL ...
- Android入门(八):使用RadioGroup 和RadioButton组件建立单选清单
这一章,我们学习RadioGroup 和RadioButton组件,我们新建一个项目,编码过程与前几章的项目类似. 1.建立字符串资源文件strings.xml: <resources> ...
- Android 使用RadioGroup和RadioButton实现单选效果
RadioButton和CheckBox的区别:CheckBox选中之后可以直接取消,RadioButton选中之后不能直接取消,所以一般情况下不建议单独使用.1.RadioGroup:RadioBu ...
- Android学习之RadioGroup和RadioButton
转载自:http://my.oschina.net/amigos/blog/59261 实现RadioButton由两部分组成,也就是RadioButton和RadioGroup配合使用.RadioG ...
- android单选按钮选择,RadioGroup,radioButton
android单选按钮选择,RadioGroup,radioButton 14. 四 / android基础 / 没有评论 单选布局绑定 如何识别选择
- ANDROID L——Material Design详解(UI控件)
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! Android L: Google已经确认Android L就是Android Lolli ...
随机推荐
- Linux高级变量
http://blog.chinaunix.net/uid-27040051-id-3450991.html 高级变量 基本形式 [1].变量扩展 格式 ${变量名称} [2].命令扩展 格式 $(命 ...
- 自用java字符串工具类
不断封装一些常用的字符串操作加到这个工具类里,不断积累: package com.netease.lede.qa.util; import java.text.ParseException; impo ...
- 客服端调用自定义宿主的WCF报错"没有终结点在侦听可以接受消息的http://localhost:8085/mex。这通常是由于不正确的地址或者 SOAP 操作导致的错误"的解决方案。
没有终结点在侦听可以接受消息的http://localhost:8085/mex.这通常是由于不正确的地址或者 SOAP 操作导致的错误. 这个错误是由于没有启动元数据交换终结点(MEX)导致的.在宿 ...
- C#控制台基础 函数的参数是接口 实现接口的类都可以作为参数,很好用
镇场诗: 大梦谁觉,水月中建博客.百千磨难,才知世事无常. 今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ 1.代 ...
- N年后给自己一些忠诚的建议
给自己S年后的一封信: 也许,现在的自己已经经历了种种历练,或成为干将,许是拔杆而起的创业者,再者仍然是一名奋斗中的工薪族.无论现在如何,请记得: M年前,自己坐在小房子里写下的信件. 那时候,自己是 ...
- 【Unity3D游戏开发】Application.systemLanguage无法区分简体中文和繁体中文 (二六)
游戏发布,语言本地化需要繁体中文和简体中文 iOS8版本之前没问题,iOS9上无法正常识别这两种语言 原因是在iOS9上,Unity通过Application.systemLanguage返回的简体中 ...
- Trigger Execution Sequence Of Oracle Forms
Sequence of triggers fires on Commit.1. KEY Commit2. Pre Commit3. Pre/On/Post Delete4. Pre/On/Po ...
- 哈理工软件学院"兆方美迪"杯第六届程序设计大赛【高年级组】--决赛 题解
比赛链接:http://acm-software.hrbust.edu.cn/contest.php?cid=1082 A.好SB啊真是,还以为lis-数有多少个数不一样. #include < ...
- Photoshop CS6 快捷键
1.工具箱 移动工具 [V]矩形.椭圆选框工具 [M]套索.多边形套索.磁性套索 [L]快速选择工具.魔棒工具 [W] 裁剪.透视裁剪.切片.切片选择工具 [C]吸管.颜色取样器.标尺.注释.12 ...
- ABAP RFC远程调用
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...