分类:C#、Android、VS2015;

创建日期:2016-02-07

一、简介

1、CheckBox

复选

【Checked】属性:是否选中。

2、RadioButton

单选

【Checked】属性:是否选中。

【RadioGroup】属性:RadioButton的分组容器。注意必须将RadioButton包含在RadioGroup内。

二、示例4—Demo04CheckBoxRadioButton

1、运行截图

2、添加demo04_CheckBoxRadioButton.axml文件

在layout文件夹下添加该文件。

从【工具箱】中向设计界面拖放2个【CheckBox】控件,1个【RadioGroup】控件,然后直接在【源】中将其修改为下面的内容:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><CheckBoxandroid:text="红色"android:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/checkBoxRed" /><CheckBoxandroid:text="绿色"android:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/checkBoxGreen" /><RadioGroupandroid:minWidth="25px"android:minHeight="25px"android:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/radioGroupGander"><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:checked="true"android:text="男"android:id="@+id/radioButtonMale" /><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="女"android:id="@+id/radioButtonFamale" /></RadioGroup><Buttonandroid:id="@+id/btnOK"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="确定" />
</LinearLayout>

3、添加Demo04CheckBoxRadioButton.cs文件

在SrcActivity文件夹下添加该文件。

using System;
using Android.App;
using Android.OS;
using Android.Widget;namespace ch05demos.SrcActivity
{[Activity(Label = "CheckBoxRadioButtonDemo")]public class Demo04CheckBoxRadioButton : Activity{CheckBox red, green;RadioButton nan, nv;protected override void OnCreate(Bundle savedInstanceState){base.OnCreate(savedInstanceState);SetContentView(Resource.Layout.demo04_CheckBoxRadioButton);red = FindViewById<CheckBox>(Resource.Id.checkBoxRed);green = FindViewById<CheckBox>(Resource.Id.checkBoxGreen);nan = FindViewById<RadioButton>(Resource.Id.radioButtonMale);nv = FindViewById<RadioButton>(Resource.Id.radioButtonFamale);var button = FindViewById<Button>(Resource.Id.btnOK);button.Click += Button_Click;}private void Button_Click(object sender, EventArgs e){string s1 = "性别:" + (nan.Checked ? "男" : "女");string s2 = "喜欢的颜色:";if (red.Checked) s2 += red.Text;if (green.Checked) s2 += " " + green.Text;Toast.MakeText(this,string.Format("{0}\n{1}", s1, s2),ToastLength.Long).Show();}}
}

运行观察该例子的效果。

提示:通过【Checked】属性或Toggle()方法都可以改变RadioButton的状态。

【Android】5.3 单选和复选相关推荐

  1. 如何在Android Studio使用单选和复选框

    教学案例:设置个人基本信息 1.新建安卓项目 基于- Empty Activity模板创建安卓应用 - SetBasicInformation 2.准备一张图像素材 将背景图片拷贝到drawable目 ...

  2. Android CheckedTextView 实现单选与多选

    以下demo 地址 单选与双选实现的效果如下 CheckedTextView 继承的是 TextView 实现 Checkable 具有TextView 的属性 一般使用结合ListView xml ...

  3. 单选不生效为什么_单选、复选、switch、tabs、标签别傻傻分不清

    设计师经常在选用单选还是复选.switch开关?不懂怎么用,请看下文. 单选:只能选一项,且必须此选项可见 摘自百度百科 常用用于B端业务,web端常用.一般长这样: 图片摘自网络 iOS和andro ...

  4. 改变单选或者复选框的样式

    原理是通过定位把以前的样式覆盖掉,就酱... 代码如下: css.checkbox{position: relative;padding-left: 8px;}.checkbox:before{con ...

  5. php一些单选、复选框的默认选择方法(示例)

    转载 http://www.php.cn/php-weizijiaocheng-360029.html 一. radio和checkbox及php select默认选择的实现代码 1.radio单选框 ...

  6. 选下拉框的的值对应上传相应的图片_vue.js如何拿到多种类型表单值提交到后台,包含上传图片、单选、复选、文本框、下拉列表框...

    2016-01-17 编辑更新 vue.js如何拿到多种类型表单值提交到后台,包含上传图片.单选.复选.文本框.下拉列表框 下面的html包括多种类型的表单,其中包括图片上传,如何拿到这些表单的值提交 ...

  7. Python3+Selenium3+webdriver学习笔记8(单选、复选框、弹窗处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记8(单选.复选框.弹窗处理)''' from selenium ...

  8. jQuery 单选框/复选框美化

    对于前端萌新来说,美化表单是个痛苦的事情,通常都是去寻找插件这种逃避的办法,其实这并不是难事.在上篇文章中提到了兄弟元素选择器在表单美化中表现突出,下面的示例源码将体现 基础篇知识的实际应用. 纯CS ...

  9. JQuery获取选中的元素(单选框复选框)及其他等

    看注释 <!DOCTYPE html> <html><head><meta charset="utf-8"><title> ...

  10. android的listview多选功能,Android ListView实现单选及多选等功能示例

    本文实例讲述了Android ListView实现单选及多选等功能的方法.分享给大家供大家参考,具体如下: 在项目中也遇到过给ListView的item添加选择功能.比如一个网购APP,有个历史浏览页 ...

最新文章

  1. 百度飞桨入选互联网领先科技成果,王海峰:AI进入工业化大生产新阶段
  2. java多线程发布订阅,多线程实现发布订阅升级版---遗留问题
  3. 【echart数组数据】echarts两条或两条以上x轴不同的线合并x轴 含有不连续数据
  4. ext的另一个table布局的例子
  5. 算法设计与分析——递归与分治策略——循环日程赛
  6. IAR astyle代码美化
  7. exec vs sp_executesql
  8. Android 仿360桌面小人
  9. CSDN小秘书 测试版
  10. 爬虫笔记9:session在突破12306图片验证中的作用
  11. FusionChartsFree的用法
  12. java pdf 转tif_使用java对pdf转成tiff文件
  13. 比亚迪宋Pro电路图和维修手册
  14. 【HDL】Verilog HDL仿真工具iverilog(Icarus Verilog)
  15. 我对锤子ROM 功能的看法——功能篇
  16. 服务器ping值不稳定,服务器网络ping值过高的原因
  17. 单摆测重力加速度的算法(Python)
  18. 关于Oralce OAM/OIM及与P6/Unifier 集成SSO的想法
  19. 18计算机考试试题答案解析,2012年计算机一级MSoffice试题及答案解析(18)
  20. ASDL宽带自动连接程序。解决每次手动连接之忧。

热门文章

  1. Linux/Debian/Ubuntu报错解决:W: Target Packages (main/binary-amd64/Packages) is configured multiple times
  2. 大数据学习笔记一:大数据的发展历程--MapReduce,Hive,Yarn,Hadoop,Spark,Flink
  3. 学硕计算机306分调剂,考研学硕可调剂专硕 需符合两个条件
  4. 第一个java_第一个java程序
  5. mysql 导入数据 1215_12、mysql导入数据
  6. instancesRespondToSelector与respondsToSelector的区别
  7. hadoop job 数量_大数据Hadoop常见面/笔试题
  8. 快速交付 敏捷开发的特点_什么是敏捷开发?它有什么特点
  9. python模糊查找文件夹名字_python实现在目录中查找指定文件的方法
  10. ubuntu java反编译,[原创]Ubuntu下简单配置反编译工具以及其开发环境