从零开始学android<RadioButton单选按钮的使用.七.>
来源:互联网 发布:淘宝广告自己跳出来 编辑:程序博客网 时间:2024/05/16 05:17
单选钮在开发中提供了一种多选一的操作模式,也是经常见到的一种组件,例如:在选择文件编码的时候只能从多种编码中选择一种,或者是选择性别的时候只能从“男”或“女”之中选择一个,而在Android中可以使用RadioGroup来定义单选钮组件,此类的定义如下:
java.lang.Object
↳android.view.View
↳android.view.ViewGroup
↳android.widget.LinearLayout
↳android.widget.RadioGroup
Radiogroup常用的方法如下
No.
方法
类型
描述
1
public void check (int id)
普通
设置要选中的单选钮编号
2
public void clearCheck ()
普通
清空选中状态
3
public int getCheckedRadioButtonId()
普通
取得选种按钮的RadioButton的ID
4
public void setOnCheckedChangeListener(
RadioGroup.OnCheckedChangeListener listener)
普通
设置单选钮选中的操作事件
RadioGroup提供的只是一个单选钮的容器,只有在此容器之中配置多个按钮组件之后才可以使用,而要想设置单选钮的内容,则需要使用RadioButton类,此类定义如下:
java.lang.Object
↳android.view.View
↳android.widget.TextView
↳android.widget.Button
↳android.widget.CompoundButton
↳android.widget.RadioButton
用一个例子简单说明
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView //提示框 android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="请选择您的性别" /><RadioGroup//包裹RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:checkedButton="@+id/male" > <RadioButton //第一个选项 android:id="@+id/male" android:text="男"/><RadioButton //第二个选项 android:id="@+id/fmale" android:text="女"/> </RadioGroup></LinearLayout>JAVA文件不用进行配置。
当然,大家也可以配置呢多个RadioButton的选项,也可以配置第一个RadioGroup。大家下面可以自己试试
下节预报:CheckBox复选框的使用。
0 0
- 从零开始学android<RadioButton单选按钮的使用.七.>
- Android 单选按钮RadioButton的使用
- Android 单选按钮RadioButton的使用
- 单选按钮 RadioButton 的使用
- 从零开始学android<CheckBox多选按钮的使用.八.>
- Android RadioButton 单选按钮
- 单选按钮RadioButton使用
- radioButton的使用(单选按钮的使用)
- Android教程(八)-- 单选按钮RadioButton控件的使用
- Android 改变单选按钮RadioButton的颜色
- 单选框RadioGroup,单选按钮RadioButton的使用
- 单选框RadioGroup,单选按钮RadioButton的使用
- ASP.NET中 RadioButton(单选按钮)的使用
- Android---RadioButton(单选按钮)详解
- Android入门之单选按钮(RadioButton)
- android 单选按钮 RadioGroup RadioButton
- Android---18---RadioButton单选按钮
- Android控件:RadioButton(单选按钮)
- hdu-Frosh Week(树状数组)
- 解析SGI STL 函数static void (* __set_malloc_handler(void (*__f)()))() 和其它
- 群集侦测技术Cluster Detection
- 定制你的语音识别-并行语音识别解码空间
- hdu-See you~(二维树状数组)
- 从零开始学android<RadioButton单选按钮的使用.七.>
- SQLite CC++接口介绍(二)
- 【Android UI设计与开发】第09期:Fragment+PopupWindow仿QQ空间最新版底部菜单栏
- MapReduce设计模式总结
- Java访问修饰符
- SQL Join的一些总结
- StringBuffer和StringBuilder的区别
- Hive的insert操作
- UVALive 6571 It Can Be Arranged