当前位置: 首页 > news >正文

android studio RadioButton单选按钮

1.定义
<!--单选按钮-->
<TextViewandroid:layout_marginTop="10dp"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="请选择你的性别:">
</TextView>
<RadioGroupandroid:id="@+id/rg_gender"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_marginTop="5dp"><RadioButtonandroid:id="@+id/rb_male"android:layout_width="0dp"android:layout_weight="1"android:layout_height="wrap_content"android:text="男"></RadioButton><RadioButtonandroid:id="@+id/rb_female"android:layout_width="0dp"android:layout_weight="1"android:layout_height="wrap_content"android:text="女"></RadioButton></RadioGroup><TextViewandroid:id="@+id/tv6"android:layout_marginTop="10dp"android:layout_width="match_parent"android:layout_height="wrap_content">
</TextView>

 

2.代码

RadioButton rb1 = findViewById(R.id.rb_male);
RadioButton rb2 = findViewById(R.id.rb_female);
RadioGroup rg = findViewById(R.id.rg_gender);
tv6 = findViewById(R.id.tv6);
rg.setOnCheckedChangeListener(this::onCheckedChange);
private void onCheckedChange(RadioGroup radioGroup, int i) {switch (i) {case R.id.rb_male:tv6.setText("男");break;case R.id.rb_female:tv6.setText("女");break;}}

http://www.lryc.cn/news/62858.html

相关文章:

  • AI大模型快速发展,我们该如何应对?
  • java多线程BlockingDeque的三种线程安全正确退出方法
  • 从STM32F407到AT32F407(一)
  • 【数据结构】顺序表和链表基本实现(含全代码)
  • CMake : Linux 搭建开发 - g++、gdb
  • 大数据实战 --- 美团外卖平台数据分析
  • 三大本土化战略支点,大陆集团扩大中国市场生态合作「朋友圈」
  • 为什么停更ROS2机器人课程-2023-
  • 【SpringCloud常见面试题】
  • ChatGPT+智能家居在AWE引热议 OpenCPU成家电产业智能化降本提速引擎
  • 拷贝构造函数和运算符重载
  • 本周热门chatGPT之AutoGPT-AgentGPT,可以实现完全自主实现任务,附部署使用教程
  • Mysql 优化LEFT JOIN语句
  • 全栈成长-python学习笔记之数据类型
  • 面试|兴盛优选数据分析岗
  • Redis(08)主从复制master-slave replication
  • 被chatGPT割了一块钱韭菜
  • vue3+ts+pinia+vite一次性全搞懂
  • Apache安装与基本配置
  • 哈夫曼树【北邮机试】
  • thinkphp:数值(保留小数点后N位,四舍五入,左侧补零,格式化货币,取整,生成随机数,数字与字母进行转换)
  • 用Flutter你得了解的七个问题
  • Nmap使用手册
  • 基于ResNet-attention的负荷预测
  • 华为校招机试 - 批量初始化次数(20230426)
  • WhatsApp CRM:通过 CRM WhatsApp 集成向客户发送消息
  • SOLIDWORKS Electrical无缝集成电气和机械设计
  • Numpy从入门到精通——数组变形|合并数组
  • DJ4-5 路由算法:LS 和 DV
  • python图像处理之形态学梯度、礼帽、黑帽