第12章:单选扭(RadioButton)和复选框(CheckBox)的功能和用法
来源:互联网 发布:php网页聊天室原理 编辑:程序博客网 时间:2024/06/04 21:18
今天主要讲的就是RadioButton和CheckBox的用法。
首先看名字就知道它们肯定是继承了Button类,可以使用Button的各种属性和方法。但是他们又多了个可以选择的功能。
RadioButton是单选按钮,也就是说一组RadioButton只能选择一个,所以 ,一组RadioButton写在一个RadioGroup下面,CheckBox是多选按钮,所以,每个CheckBox都要单独写。下面我们以一个实例来看看他们的用法和功能。
这里建立的唯一标识是cn.edu.hpu.acm.checkButtonTest
string.xml
<resources> <string name="app_name">单选、多选框</string> <string name="hello_world">Hello world!</string> <string name="action_settings">Settings</string> <string name="sex">性别</string> <string name="male">男</string> <string name="female">女</string> <string name="likeColor">喜欢的颜色</string> <string name="red">红色</string> <string name="blue">蓝色</string> <string name="green">绿色</string> <string name="result1">你的性别是女人</string> <string name="result2">你的性别是男人</string> <string name="redResult">你喜欢红色</string> <string name="blueResult">你喜欢蓝色</string> <string name="greenResult">你喜欢绿色</string> <string name="title_activity_other">OtherActivity</string></resources>
activity_main.xml
<TableLayout 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:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <TableRow> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/sex"/> <RadioGroup android:id="@+id/rg"> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/male" android:text="@string/male"/> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/female" android:text="@string/female"/> </RadioGroup> </TableRow> <TableRow> <TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:text="@string/likeColor"/> <LinearLayout android:orientation="vertical" android:layout_height="wrap_content" android:layout_width="wrap_content"> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/red" android:text="@string/red"/> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/blue" android:text="@string/blue"/> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/green" android:text="@string/green"/> </LinearLayout> </TableRow> <TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/show"/></TableLayout>
布局截图
以上已经实现了主要功能,最后一个按钮写的是跳转,没什么实际意义,可以带值跳过去,不过意义不大,并且那个布局及Java代码都没几行,所以就看以上就可以了。
0 0
- 第12章:单选扭(RadioButton)和复选框(CheckBox)的功能和用法
- 单选框(RadioButton)和复选框(CheckBox)的功能与用法
- 利用单选钮、复选框获取用户信息(radiobutton checkbox的功能和用法)
- 单选按钮(RadioButton)与 复选框(CheckBox)的功能与 用法
- 单选按钮(RadioButton)与复选框(CheckBox)的功能与用法
- Android—RadioButton(单选框)和CheckBox(复选框)
- ABAP 中checkbox 和 RADIOBUTTON (复选框和单选框)的部分区别
- 初学单选框RadioButton和复选框CheckBox
- 单选框(RadioButton)和复选框(CheckBox)
- 【8】CheckBox(复选框)和RadioButton(单选按钮)
- Android--CheckBox复选框、RadioGroup和RadioButton及其使用
- Android-单选按钮RadioButton和复选框checkbox
- Android组件复习之基本组件02—单选按钮(RadioButton)和复选框(CheckBox)
- Android组件复习之基本组件02—单选按钮(RadioButton)和复选框(CheckBox)
- Android UI 详解之单选(RadioButton)和复选(CheckBox)
- android单选按钮(RadioButton)、复选框(CheckBox)
- Android的RadioButton和checkBox的用法-android学习之旅(十九)
- RadioButton和CheckBox的区别,RadioButton&RadioGroup
- HDU2303(数论)大整数求余+素数筛选
- [Tyvj 1729]文艺平衡树
- centos install (PHP+Mysql+apache)
- POJ 1922 Ride to School 简单模拟
- C++ 指针函数介绍
- 第12章:单选扭(RadioButton)和复选框(CheckBox)的功能和用法
- 双指针
- HDU 1406 完数
- QT下实现将图片从一个文件拷贝到另一个文件夹
- Windows下命令安装MySQL.zip压缩包以及修改MySQL密码
- swirl 6: Subsetting Vectors
- sendmail 发送html 的邮件
- hdu5277 YJC counts stars(最大团)
- [LeetCode]Contains Duplicate II