界面:

<?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. 二叉搜索树(python)

    # -*- coding: utf-8 -*- class BSTNode(object): def __init__(self, key, value, left=None, right=None) ...

  2. MySQL批量修改相同后缀表名

    执行步骤 1.用concat批量生成修改表名的语句 SELECT CONCAT( 'ALTER TABLE ', table_name, ' RENAME TO ', ,locate('_postfi ...

  3. 微信小程序之循环<block></block>

    (1)<block></block>标签 block常用于结合循环 <block wx:for="{{array}}" wx:key="{{ ...

  4. 如何解决WinForm中TableLayout控件闪烁的问题

    public FormReg() { InitializeComponent(); typeof(TableLayoutPanel) .GetProperty("DoubleBuffered ...

  5. Spring -13 -Spring 中常用注解总结

    1.@Component 创建类对象,相当于配置<bean/> 2.@Service 与@Component 功能相同. 2.1都写在ServiceImpl 类上. 3.@Reposito ...

  6. 01.Vue前端路由学习目标

    路由的基本概念与原理 vue-router的基本使用 vue-router嵌套路由 vue-router动态路由匹配 vue-router命名路由 vue-router编程式导航 基于vue-rout ...

  7. postgresql —— 表的继承

    示例: CREATE TABLE cities ( --父表 name text, population float, altitude int ); CREATE TABLE capitals ( ...

  8. oracle删除重复数据,只保留一条

    比如,某个表要按照id和name重复,就算重复数据 delete from 表名 where rowid not in (select min(rowid) from 表名 group by id,n ...

  9. RookeyFrame 线下 添加Model

    1.在Model层添加一个类,继承BaseEntity,如: (将就demo里面的类改了一下) using Rookey.BusSys.Model.Base; using Rookey.BusSys. ...

  10. TPS与QPS,以及GMV

    TPS是指每秒处理事务的个数,处理的载体可以是单台服务器,也可以是一个服务器集群. 例如:下单接口,一秒内,下单完成次数为1000,则下单接口总 tps = 1000,共有10台服务器提供下单服务,单 ...