界面:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="12dp">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="性别:"/>
<!-- 定义一组单选钮 -->
<RadioGroup android:id="@+id/rg"
android:orientation="horizontal"
android:layout_gravity="center_horizontal">
<!-- 定义两个单选钮 -->
<RadioButton android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/male"
android:text="男"
android:checked="true"/>
<RadioButton android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/female"
android:text="女"/>
</RadioGroup>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="喜欢的颜色:" />
<!-- 定义一个垂直的线性布局 -->
<LinearLayout android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- 定义三个复选框 -->
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="红色"
android:checked="true"/>
<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="绿色"/>
</LinearLayout>
</TableRow>
<TextView
android:id="@+id/show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</TableLayout>

我们对radioGrop绑定一个监听函数,当它的check值改变的时候触发:

val rg = findViewById<RadioGroup>(R.id.rg)
val show = findViewById<TextView>(R.id.show)
//对 radioGroup绑定一个监听函数
rg.setOnCheckedChangeListener{group,checkId->
val tip = if(checkId==R.id.female) "您的性别是女生"
else "您的性别是男生生"
show.text=tip

radioButon的使用的更多相关文章

  1. Android 控件属性介绍

    1.LinearLayout(线性布局): 可以分为水平线性:android:orientation= " horizontal " 和垂直线性:android:orientati ...

  2. WPF自定义控件与样式(4)-CheckBox/RadioButton自定义样式

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: Che ...

  3. 单选按钮(RadioButton)与复选框(CheckBox)的功能与用法

    单选按钮(RadioButton)和复选框(CheckBox).状态开关按钮(ToggleButton)与开关(Switch)是用户界面中最普通的UI组件,他们都继承了Button类,因此都可直接使用 ...

  4. 【转】WPF自定义控件与样式(4)-CheckBox/RadioButton自定义样式

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等 本文主要内容: CheckBox复选框的自定义样式,有两种不同的风格实现: RadioB ...

  5. Android中控件属性详细总结(转载)

    转载地址:https://www.cnblogs.com/nanguojs/p/5950510.html 1.LinearLayout(线性布局): 可以分为水平线性:android:orientat ...

  6. Android布局属性与常用控件

    一.Android常用布局属性 1. LinearLayout的特有属性 android:orientation:设置布局排列方式   android:layout_weight:设置所占布局的权重  ...

  7. Android常用布局和控件

    一.Android常用布局属性 1. LinearLayout的特有属性 android:orientation:设置布局排列方式   android:layout_weight:设置所占布局的权重  ...

随机推荐

  1. jenkins+ant+jmeter接口自动化的持续集成

    一.jmeter.jenkins安装 这里不再说明,请看上一个随笔!!! 链接:https://www.cnblogs.com/magicYJ/p/11839646.html 二.ant安装 下载地址 ...

  2. mysql 数据库的时间与字符串转换

    .当前日期.时间 now() 获取 当前日期和时间 :: curdate() 当前日期, curtime() 当前时间 :: current_time() : //同curtime(),current ...

  3. 手写热更新阐述tinker实现原理

    关于热更新如今面试也是基本上都会提及到的,我上一家公司用的是tinker,而这里准备研究的也是它的原理,而关于tinker的原理网上也是一大堆文章进行介绍,为了对它有个更加进一步的认识,所以自己动手来 ...

  4. 51nod 2494 最长配对

    小b有一个01序列,她想找到一个最长的区间使得这个区间的01能两两配对,即0的个数和1的个数相等.求最长区间的长度. 收起   输入 第一行一个正整数n,表示数组长度,其中0<n≤50000: ...

  5. VS调试web api服务

    vs2013开发web api service时,使用vs开发服务器调试没有问题,但将项目放到另一台电脑调试(vs2010),总会提示 无法再以下端口启动asp.net开发服务器 错误:通常每个套接字 ...

  6. HDU - 4352 - XHXJ's LIS(数位DP)

    链接: https://vjudge.net/problem/HDU-4352 题意: a 到 b中一个数组成递增子序列长度等于k的数的个数 思路: 因为只有10个数,使用二进制维护一个递增序列,每次 ...

  7. Oracle ALERT日志中常见监听相关报错之二:ORA-3136错误的排查 (转载)

    近期在多个大型系统中遇到此问题,一般来说如果客户端未反映异常的话可以忽略的.如果是客户端登陆时遇到ORA-12170: TNS:Connect timeout occurred,可以参考 http:/ ...

  8. Linux命令:awk求和、平均值、最大最小值

    本文链接:https://blog.csdn.net/wyqwilliam/article/details/825600431.求和cat data|awk '{sum+=$1} END {print ...

  9. QMutexLocker基于QMutex的便利类

    首先需要注意的是:QMutexLocker这个类是基于QMutex的便利类,这个类不能够定义   私有成员变量  和  全局变量,只能够定义局部变量来使用. 使用方法:(1)先定义一个QMutex类的 ...

  10. Python学习之--列表

    一.列表表示: 用方括号([] )来表示列表,并用逗号来分隔其中的元素,索引从0开始,如下 二.修改元素 三.添加元素: 1. append 2. insert 四. 删除元素: 1. del 2. ...