iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >Android学习笔记(五)——RadioGroup&RadioButton
  • 678
分享到

Android学习笔记(五)——RadioGroup&RadioButton

android学习radiobuttonradiogroupAndroid 2022-06-06 13:06:14 678人浏览 安东尼
摘要

实现RadioButton由两部分组成,也就是RadioButton和RadioGroup配合使用. RadioGroup是单选组合框,可以容纳多个RadioButton的容器. 在没有RadioGroup的情况下,RadioBut

实现RadioButton由两部分组成,也就是RadioButton和RadioGroup配合使用. RadioGroup是单选组合框,可以容纳多个RadioButton的容器. 在没有RadioGroup的情况下,RadioButton可以全部都选中 当多个RadioButton被RadioGroup包含的情况下,RadioButton只可以选择一个。

Xml代码

       //竖直方向摆放

效果:

在这里插入图片描述

自定义RadioButton


在drawable中自定义背景:


          //选中的效果
      //未选中的效果

效果展示:

在这里插入图片描述

设置监听事件

private RadioGroup mRg1;
mRg1=(RadioGroup)findViewById(R.id.rg_1);
mRg1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){   //被选择的监听器
      @Override
      public void onCheckedChanged(RadioGroup group, int checkedId) {  //参数:被选择的按钮所在的组,id
            RadioButton radioButton=(RadioButton)group.findViewById(checkedId);     //根据被选择按钮的ID找到被选择按钮
            Toast.makeText(RadioButtonActivity.this,radioButton.getText(),
            Toast.LENGTH_SHORT).show();         //设置提示信息
            }
        });

在这里插入图片描述


作者:Nuyoahgyc


--结束END--

本文标题: Android学习笔记(五)——RadioGroup&RadioButton

本文链接: https://www.lsjlt.com/news/29384.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作