RadioButton和checkBox简介

单选按钮(RadioButton)和复选框(CheckBox)都继承了Button,因此属性的设置和Button差不多,只是加了一个android:chencked属性。

用来设置是否被选中。

RadioButton和checkBox的区别

前者如果一组只能只能选中一个,一次通常会与RadioGroup一块使用,后者没有限制。

实例

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
    android:orientation="vertical">
  <TableRow android:layout_width="wrap_content"
      android:layout_height="wrap_content">
      <TextView android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="性别:"
          android:textSize="16px"/>
      <RadioGroup
          android:orientation="horizontal"
          android:id="@+id/rg"
          android:layout_gravity="center_horizontal"
          android:layout_width="match_parent"
          android:layout_height="wrap_content">
          <RadioButton
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="男"
              android:checked="true"/>
          <RadioButton
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="女"
              />
          </RadioGroup>
  </TableRow>
    <TableRow android:layout_height="wrap_content"
        android:layout_width="wrap_content">
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="喜欢的颜色"
            android:textSize="16px"/>
        <CheckBox android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="红色"/>
        <CheckBox android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="蓝色"/>
        <CheckBox android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="绿色"/>
    </TableRow>
    <TableRow android:layout_height="match_parent"
        android:layout_width="match_parent">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="show"/>
    </TableRow>
</LinearLayout>

效果图

Android的RadioButton和checkBox的用法-android学习之旅(十九)的更多相关文章

  1. Android的搜索框SearchView的用法-android学习之旅(三十九)

    SearchView简介 SearchView是搜索框组件,他可以让用户搜索文字,然后显示.' 代码示例 这个示例加了衣蛾ListView用于为SearchView增加自动补全的功能. package ...

  2. 【转】 Pro Android学习笔记(十九):用户界面和控制(7):ListView

    目录(?)[-] 点击List的item触发 添加其他控件以及获取item数据 ListView控件以垂直布局方式显示子view.系统的android.app.ListActivity已经实现了一个只 ...

  3. Android学习路线(十九)支持不同设备——支持不同(Android)平台版本号

    当最新的Android版本号为你的应用提供着非常棒的APIs时.你却要在很多其它的设备更新之前继续支持老的系统版本号.这篇课程怎样在继续支持低版本号的系统的情况下使用新版本号的高级API. Platf ...

  4. Android学习笔记(十九)——内容提供器

    //此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! 内容提供器(Content Provider)主要用于在不同的应用程序之间实现数据共享的功能,它提供了一套完整 ...

  5. android 学习随笔二十九(自定义监听 )

    package com.itheima.momo.dialog; import com.itheima.momo.R; import android.app.AlertDialog; import a ...

  6. Android的ViewAnimator而它的子类ViewSwitcher-android学习之旅(三十三)

    ViewAnimator遗传FrameLayout,重合使用多个组件.可以增加部件数量,然后会有时间切换动画. ViewAnimator及其子类的继承关系 ViewAnimator经常使用属性 Vie ...

  7. 从零開始学android&lt;mediaplayer自带播放器(视频播放).四十九.&gt;

    MediaPlayer除了能够对音频播放之外,也能够对视频进行播放,可是假设要播放视频仅仅依靠MediaPlayer还是不够的.还须要编写一个能够用于视频显示的空间,而这块显示空间要求能够高速的进行G ...

  8. Android数据库Sqlite-android学习之旅(九)

    简介 sqilte是一个轻量级的数据库,满足数据库的基本操作,由于移动端的内存有限,所以sqilte刚好能满足移动端开发的基本要求. 废话不多说,上代码 1.首先介绍一下,sqlite的管理类SQLi ...

  9. Android学习笔记(十九) OkHttp

    一.概述 根据我的理解,OkHttp是为了方便访问网络或者获取服务器的资源,而封装出来的一个工具包.通常的使用步骤是:首先初始化一个OkHttpClient对象,然后使用builder模式构造一个Re ...

随机推荐

  1. 【NOIP2017 OFO】

    ·奇怪的标题可能预示着这一篇博文不是讲算法或者分享题目的吧. [一只情绪化的兔子]      今年的11月12日出奇地比去年温暖.两场比赛结束后的我们在临走前去尝试了OFO共享单车,在成都电子科技大学 ...

  2. hdu 5120(2014北京—求圆相交)

    题意:求环的相交面积 思路: 通过画图可知,面积= 大圆相交面积 - 大小圆相交面积*2 + 小小圆相交面积  再通过圆相交模板计算即可 #include <iostream> #incl ...

  3. hdu 1402 FFT(模板)

    A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  4. bzoj4517排列计数 错排+组合

    4517: [Sdoi2016]排列计数 Time Limit: 60 Sec  Memory Limit: 128 MBSubmit: 1491  Solved: 903[Submit][Statu ...

  5. 使用jquery.qrcode.js生成二维码

    通常生成二维码的方式有两种:第一种是java代码的形式,第二种是通过Js方式. 在这里我做个记录,用js生成二维码,可以在官网下载源码:http://jeromeetienne.github.io/j ...

  6. Mysql参数汇总

    凡是需要耐心. 参数为静态参数则黄色字体标记. 参数为全局变量则粗体标记. 参数为全局.会话变量则不标记. auto_increment_increment auto_increment_offset ...

  7. (转载)总结一下SQL语句中引号(')、quotedstr()、('')、format()在SQL语句中的用法

    总结一下SQL语句中引号(').quotedstr().('').format()在SQL语句中的用法以及SQL语句中日期格式的表示(#).('')在Delphi中进行字符变量连接相加时单引号用('' ...

  8. redis锁处理并发问题

    redis锁处理并发问题 redis锁处理高并发问题十分常见,使用的时候常见有几种错误,和对应的解决办法. set方式 setnx方式 setnx+getset方式 set方式 加锁:redis中se ...

  9. ORACLE设置自启动记录

    设置开机自启动1. 修改Oracle系统配置文件:/etc/oratab,只有这样,Oracle 自带的dbstart和dbshut才能够发挥作用.[root@hailiang ~]# vi /etc ...

  10. 【python进阶】Garbage collection垃圾回收2

    前言 在上一篇文章[python进阶]Garbage collection垃圾回收1,我们讲述了Garbage collection(GC垃圾回收),画说Ruby与Python垃圾回收,Python中 ...