Radio 和 check 控件
来源:互联网 发布:中国移动网络建设 编辑:程序博客网 时间:2024/06/01 04:00
原创:kylin_zeng http://blog.chinaunix.net/uid/23795897.html在此感谢mars 老师的帮助,
转载请注明原创出处,尊重他人的劳动成果。
1、radioGroup: 这个组只能选择其中一个。
<RadioGroup
android:id="@+id/genderGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RadioButton // 一个组里面有两个button,如男
android:id="@+id/femaleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/female"
/>
<RadioButton // 如女,
android:id="@+id/maleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/male"
/>
</RadioGroup>
2、checkBox: 这个都可以选
<CheckBox
android:id="@+id/swim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/swim"
/>
<CheckBox
android:id="@+id/run"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/run"
/>
<CheckBox
android:id="@+id/read"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/read"
/>
3、先声明:
private RadioGroup genderGroup = null;
private RadioButton femaleButton = null;
private RadioButton maleButton = null;
private CheckBox swimBox = null;
private CheckBox runBox = null;
private CheckBox readBox = null;
4、在onCreate里面 初始化:
genderGroup = (RadioGroup)findViewById(R.id.genderGroup);
femaleButton = (RadioButton)findViewById(R.id.femaleButton);
maleButton = (RadioButton)findViewById(R.id.maleButton);
swimBox = (CheckBox)findViewById(R.id.swim);
runBox = (CheckBox)findViewById(R.id.run);
readBox = (CheckBox)findViewById(R.id.read);
5、Radio 组设置一个监听器:
genderGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { //当radio里面的选择改变时,就会进入这里。
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
if(femaleButton.getId() == checkedId){
System.out.println("famale");
Toast.makeText(RadioTest.this, "famle", Toast.LENGTH_SHORT).show();
}
else if(maleButton.getId() == checkedId)
{
System.out.println("male");
}
}
});
6、checkbox 分别设置监听器:
//为多选按钮添加监听器
swimBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // 单swimBox点击的时候,无论是打勾还是去掉勾
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked) //打勾
{
System.out.println("swim is checked");
}
else //去掉勾
{
System.out.println("swim is unchecked");
}
}
});
runBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked)
{
System.out.println("run is checked");
}
else
{
System.out.println("run is unchecked");
}
}
});
mars视频教程ppt和代码01_12_src.zip
转载请注明原创出处,尊重他人的劳动成果。
1、radioGroup: 这个组只能选择其中一个。
<RadioGroup
android:id="@+id/genderGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RadioButton // 一个组里面有两个button,如男
android:id="@+id/femaleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/female"
/>
<RadioButton // 如女,
android:id="@+id/maleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/male"
/>
</RadioGroup>
2、checkBox: 这个都可以选
<CheckBox
android:id="@+id/swim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/swim"
/>
<CheckBox
android:id="@+id/run"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/run"
/>
<CheckBox
android:id="@+id/read"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/read"
/>
3、先声明:
private RadioGroup genderGroup = null;
private RadioButton femaleButton = null;
private RadioButton maleButton = null;
private CheckBox swimBox = null;
private CheckBox runBox = null;
private CheckBox readBox = null;
4、在onCreate里面 初始化:
genderGroup = (RadioGroup)findViewById(R.id.genderGroup);
femaleButton = (RadioButton)findViewById(R.id.femaleButton);
maleButton = (RadioButton)findViewById(R.id.maleButton);
swimBox = (CheckBox)findViewById(R.id.swim);
runBox = (CheckBox)findViewById(R.id.run);
readBox = (CheckBox)findViewById(R.id.read);
5、Radio 组设置一个监听器:
genderGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { //当radio里面的选择改变时,就会进入这里。
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
if(femaleButton.getId() == checkedId){
System.out.println("famale");
Toast.makeText(RadioTest.this, "famle", Toast.LENGTH_SHORT).show();
}
else if(maleButton.getId() == checkedId)
{
System.out.println("male");
}
}
});
6、checkbox 分别设置监听器:
//为多选按钮添加监听器
swimBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // 单swimBox点击的时候,无论是打勾还是去掉勾
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked) //打勾
{
System.out.println("swim is checked");
}
else //去掉勾
{
System.out.println("swim is unchecked");
}
}
});
runBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked)
{
System.out.println("run is checked");
}
else
{
System.out.println("run is unchecked");
}
}
});
mars视频教程ppt和代码01_12_src.zip
0
上一篇:android 布局
下一篇:android 水平和转圈的进度条
相关热门文章
- Java 内存模型 - jsr133 规范...
- haproxy 安装
- chemise burberry homme outle...
- Standards for the concrete b...
- How to effectively improve t...
- Android之开发环境搭建
- Android自定义View的实现...
- AndroidManifest.xml配置文件...
- Android源码调试方法详解...
- 不用vs和cygwin!Eclipse+cdt...
- 请问Linux默认shell的是什么 ...
- 谁能够帮我解决LINUX 2.6 10...
- 现在的博客积分不会更新了吗?...
- shell怎么读取网页内容...
- ssh等待连接的超时问题...
给主人留下些什么吧!~~
评论热议
0 0
- Radio 和 check 控件
- Ext:Radio check后显示和隐藏控件错误的问题
- 鸡啄米vc++2010系列21(按钮控件Button、Radio Button和Check Box)
- VS2010/MFC编程入门之二十一(常用控件:按钮控件Button、Radio Button和Check Box)
- VS2010/MFC编程入门之二十一(常用控件:按钮控件Button、Radio Button和Check Box)
- VS2010/MFC编程入门之二十二(常用控件:按钮控件Button、Radio Button和Check Box)
- VS2013/MFC编程入门之二十一(常用控件:按钮控件Button、Radio Button和Check Box)
- C++ MFC / VS2013 之二十(常用控件:按钮控件Button、Radio Button和Check Box)
- radio控件和checkbox实例
- Ext中checkbox和radio捕获check事件
- 【Flex】菜单中的分割线和Check Radio
- jquery获取和设置radio,check,select选项
- jquery获取和设置radio,check,select选项
- jquery获取和设置radio,check,select选项
- jquery获取和设置radio,check,select选项
- jquery获取和设置radio,check,select选项
- jquery获取和设置radio,check,select选项
- java script check radio
- ISO8859-1、UTF-8 与GB2312
- nandflash 详解
- 修改Tomcat窗口名称
- 手机视频录制功能
- android 布局
- Radio 和 check 控件
- debian源码制作*.deb与上传仓库安装
- android 水平和转圈的进度条
- 使用ThinkPHP框架快速开发网站(多图)
- list 控件
- Android中获取应用程序(包)的大小-----PackageManager的使用(二)
- android 操作数据库
- 第十七周项目6-学生成绩统计(5)
- Centos下服务器版本安装mysql
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
梦特娇鞋子多少钱
正品梦特娇男装
梦特娇 价格
正品梦特娇
梦特娇属于什么档次
梦特娇女包什么档次
montagut
梦得娇
超梦特性
超梦特性哪个好
男人梦到蛇缠身是什么梦
梦被蛇咬手
梦到蛇是胎梦吗
作梦梦见蛇是什么意思
女人梦见两条蛇是胎梦嘛
变异生物系统 梦狂风
梦王国与沉睡的100王子
梦王子安卓版下载
梦王子下载
梦100王子
丝梦王子
梦之堂
姚梦琪和夜寒轩全文
姚梦琪夜寒轩全文
天晟海琴湾
梦琴湾
香堤澜湾2期爱琴岛
碧水琴湾二手房
天妒红颜任梦老许电梯
恶梦电梯
梦百合
梦百合杯
梦百合股吧
梦百合股票
梦百合股票行情
梦百合床垫怎么样
梦百合乳胶床垫
梦百合智能床垫
梦百合记忆棉床垫
mlily梦百合
梦百合记忆棉床垫怎么样