CheckBox:复选框

有两种状态

选中状态(true),未选状态(false)

属性

android:checked= “false”(表示该复选框未被选中)

RadioGroup与RadiosButton

单独一个RadioButton一旦按下。取消是比較麻烦的。因此不建议单独使用RadioButton。

首先看RadioGroup

他是RadioButton的一个集合,提供多选一机制。

RadioGroup属性。android:orientation=”vertical”或”horizontal”

决定RadioButton的排列方式,是垂直排布或水平排布

通过详细演示样例看一下怎样监听对应事件

package com.example.checkboxandradiobox;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioGroup; public class MainActivity extends Activity implements android.widget.RadioGroup.OnCheckedChangeListener{ private RadioGroup rg;
private CheckBox checkBox;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 初始化checkBox
checkBox = (CheckBox)findViewById(R.id.checkBox1); //通过设置checkbox的监听事件来对checkbox是不是被选中
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean ischecked) {
//通过oncheckedChanged来监听当前的checkBox是否被选中
if(ischecked){
//获得checkBox的文本内容
String msg = checkBox.getText().toString();
Log.i("tag", msg);
}
}
}); //初始化RadioGroup
rg = (RadioGroup) findViewById(R.id.radioGroup1);
//实现RadioGroup的监听事件
rg.setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(RadioGroup group, int checkId) {
switch (checkId) {
case R.id.radio0:
Log.i("tag", "当前选中男孩");
break;
case R.id.radio1:
Log.i("tag", "当前选中女孩");
break;
}
} }

CheckBox和RadioButton以及RadioGroup的更多相关文章

  1. CheckBox和RadioButton

    多选按钮CheckBox的使用方法和常用的监听器:OnClickListener.OnCheckedChangeListener 在activity_main.xml中使用LinearLayout布局 ...

  2. Android零基础入门第20节:CheckBox和RadioButton使用大全

    原文:Android零基础入门第20节:CheckBox和RadioButton使用大全 本期先来学习Button的两个子控件,无论是单选还是复选,在实际开发中都是使用的较多的控件,相信通过本期的学习 ...

  3. MVC小系列(十八)【给checkbox和radiobutton添加集合的重载】

    mvc对DropDownListFor的重载很多,但对checkbox和radiobutton没有对集合的重载 所以该讲主要针对集合的扩展: #region 复选框扩展 /// <summary ...

  4. 设置ToggleButton、Switch、CheckBox和RadioButton的显示效果

    ToggleButton.Switch.CheckBox和RadioButton都是继承自android.widget.CompoundButton,意思是可选择的,因此它们的用法都很类似.Compo ...

  5. 如何在Android的ListView中构建CheckBox和RadioButton列表(支持单选和多选的投票项目示例)

    引言 我们在android的APP开发中有时候会碰到提供一个选项列表供用户选择的需求,如在投票类型的项目中,我们提供一些主题给用户选择,每个主题有若干选项,用户对这些主题的选项进行选择,然后提交. 本 ...

  6. Jquery中的CheckBox、RadioButton、DropDownList的取值赋值实现代码

    随着Jquery的作用越来越大,使用的朋友也越来越多.在Web中,由于CheckBox. Radiobutton . DropDownList等控件使用的频率比较高,就关系到这些控件在Jquery中的 ...

  7. 兔子-RadioButton和RadioGroup的关系

    RadioButton和RadioGroup的关系: 1.RadioButton表示单个圆形单选框.而RadioGroup是能够容纳多个RadioButton的容器 2.每一个RadioGroup中的 ...

  8. [安卓] 4、CheckBox、RadioButton和Toast简单用法

      和按钮类似,这里采用cb1.setOnCheckedChangeListener(this);方法分别对3个CheckBox进行CheckChange事件绑定,然后在onCheckedChange ...

  9. 【读书笔记《Android游戏编程之从零开始》】4.Android 游戏开发常用的系统控件(EditText、CheckBox、Radiobutton)

    3.4 EditText EditText类官方文档地址:http://developer.android.com/reference/android/widget/EditText.html Edi ...

随机推荐

  1. wkhtmltopdf 生成pdf

    public class PdfHelper { static string RootPath { get { string AppPath = ""; HttpContext H ...

  2. 如何捕获winform程序全局异常?(续)

    前言 上篇文章我提供了一种方案可以供我们捕获单线程程序中的所有未处理异常.但是如果程序是多线程,那么新增线程出现了异常上个方案就无能为力了.本着方案总比问题多的态度,我再给大家提供一种新的方案,供大家 ...

  3. 【虚拟化实战】容灾设计之一VR vs SRM

    作者:范军 (Frank Fan) 新浪微博:@frankfan7 从本文开始,我们将介绍一系列的关于容灾的解决方案.先探讨应用的场景,然后再深入介绍技术架构. 情景一: 某小型公司的虚拟化环境中,在 ...

  4. php调用dll

    http://download.csdn.net/detail/pinghe2005/5108556

  5. webstorm入门1-主题和配色

    1.引子 以前介绍过 Sublime text 3 系列的文章,着重介绍了 Sublime text 3 如何下载.安装.插件.配置等内容.Sublime text 3的轻量和富扩展,为前端开发带来了 ...

  6. 设计模式6:Composite

    Entry.java: package gendwang.cisco.com; public abstract class Entry { private int height = 0; privat ...

  7. Java中的throw和throws的差别

    Java中的throw和throws的差别 1.throwkeyword用于方法体内部.而throwskeyword用于方法体部的方法声明部分: 2.throw用来抛出一个Throwable类型的异常 ...

  8. 报错消息写在AT SELECTION-SCREEN OUTPUT和START-OF-SELECTION事件下的区别

    今天面试没答上来的问题,其实我是知道的,以前也遇到过.... START-OF-SELECTION下的话会在左下角报错 AT SELECTION-SCREEN OUTPUT消息会弹出框,然后点击就没有 ...

  9. .net生成Excel,并下载

    生成Excel的方式有很多种,这里记录两个最简单的: 1.将数据保存为html,然后输出到客户端,保存为Excel文件: 2.通过\t\n生成字符串,然后输出到客户端,保存为Excel. 以上两者的原 ...

  10. Transformations 方块转换

    题目是中文题,就不做什么解释了,纯模拟题,主要要搞清楚这几种装换方式下标的变化: 第一种:顺时针旋转90度: c[j][n-i+1]=a[i][j]; 第二种:旋转180度: c[n-i+1][n-j ...