>概念:从多个互斥选项中选择一个  如果是选项全部展开  RadioButton  不是展开的Spinner(下拉列表)



    >属性: android:checked="true"



    >使用方法:

         使用RadioButton要用RadioGroup进行分组 RadioGroup是LinearLayout的子类  可以控制方向

        >方式一:使用onclickListner 监听事件(点击事件)

>方式二:****使用OnCheckedChangeListener (RadioGroup)  状态改变的监听 *****

package com.fmy.a;

import android.app.Activity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast; public class MainActivity extends Activity { private RadioGroup rg;
private RadioButton zrf;
private RadioButton zxc; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.demo_textview);
rg = (RadioGroup) findViewById(R.id.rg);
zrf = (RadioButton) findViewById(R.id.zrf);
zxc = (RadioButton) findViewById(R.id.zxc);
zxc.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override //buttonView就是RadioButton对象 isChecked对象是否本选中
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Toast.makeText(MainActivity.this, "嘿嘿"+buttonView.getText().toString(), 3).show();
} });
rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//rg本身的对象 checkedId 状态被改变子id
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton rb =(RadioButton) findViewById(checkedId);
Toast.makeText(MainActivity.this, "哈哈"+rb.getText().toString(), 3).show();
}
});
} }
<?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" >
<RadioGroup
android:id="@+id/rg"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<!-- android:checked="true" 设置默认选中-->
<RadioButton
android:id="@+id/zrf"
android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="周润发" /> <RadioButton
android:id="@+id/zxc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="周星驰" />
</RadioGroup> </LinearLayout>

03 RadioButton 单选按钮的更多相关文章

  1. [tkinter]Radiobutton单选按钮的使用

    首先因为单选按钮有一个特性(一个被选中后,自动清除其它按钮的选中状态) 所以使用方式也有点不同 错误示例 from tkinter import * root = Tk() r1 = Radiobut ...

  2. android.widget.RadioButton 单选按钮(转)

    大家好,我们今天这一节要介绍的是RadioGroup 的组事件.RadioGroup 可将各自不同的RadioButton ,设限于同一个Radio 按钮组,同一个RadioGroup 组里的按钮,只 ...

  3. 控件_RadioGroup&&RadioButton(单选按钮)和Toast

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...

  4. JavaScript/JQuery radioButton(单选按钮)练习20190409

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  5. RadioButton单选按钮的使用

    namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { Initialize ...

  6. 03一些View总结

    第三天 一  TextView    父类 : View     >概念:文本控件 :文本内容的显示   默认配置不可编辑  子类EditText可以编辑          >属性:    ...

  7. [ PyQt入门教程 ] PyQt5基本控件使用:单选按钮、复选框、下拉框

    本文主要介绍PyQt5界面最基本使用的单选按钮.复选框.下拉框三种控件的使用方法进行介绍. 1.RadioButton单选按钮/CheckBox复选框.需要知道如何判断单选按钮是否被选中. 2.Com ...

  8. Android RadioButton控件

    RadioButton   单选按钮 常用属性: text 文本 checked=“true” 默认选中 一组互斥的单选按钮要放在RadioGroup中.RadioGroup常用属性: orienta ...

  9. Android Studio 之 RadioButton

    •任务 如何通过 RadioButton 实现如图所示的界面? •基本用法 RadioButton 单选按钮,就是只能够选中一个,所以我们需要把 RadioButton 放到 RadioGroup 按 ...

随机推荐

  1. ScalaPB(0): 找寻合适的内部系统微服务集成工具

    前一段时间我们探讨了SDP的一个基于集群的综合数据平台解决方案,由多种数据库组成,包括:JDBC, Cassandra 及MongoDB.其中Cassandra和MongoDB属于分布式数据库,可以在 ...

  2. HTTPS介绍

    超文本传输协议HTTP协议被用于在Web浏览器和网站服务器之间传递信息,HTTP协议以明文方式发送内容,不提供任何方式的数据加密,如果攻击者截取了Web浏览器和网站服务器之间的传输报文,就可以直接读懂 ...

  3. 《Java技术》的第二次作业

    (一)学习总结 1.什么是构造方法?什么是构造方法的重载?下面的程序是否可以通过编译?为什么? (1) 构造方法用于在创建对象时对其进行初始化,且方法名与类名相同,方法名前面没有返回值类型的声明,不能 ...

  4. A TensorBoard plugin for visualizing arbitrary tensors in a video as your network trains.Beholder是一个TensorBoard插件,用于在模型训练时查看视频帧。

    Beholder is a TensorBoard plugin for viewing frames of a video while your model trains. It comes wit ...

  5. python四则运算

    源代码已上传至Github,https://github.com/chaigee/arithmetic,中的python_ari.py文件 题目: (1)能自动生成小学四则运算题目,并且不能出现负数: ...

  6. IntelliJ IDEA光标变粗 backspace无法删除内容解决方法

    进入了vim插件 1.ctrl+alt+s快捷键打开Settings 2.选择左侧列表中的Plugins 3.在右侧面板的搜索框中搜索IdeaVim 4.将复选框中的钩子去掉 backspace成了其 ...

  7. Spring boot集成swagger2

    一.Swagger2是什么? Swagger 是一款RESTFUL接口的文档在线自动生成+功能测试功能软件. Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格 ...

  8. 通讯协议序列化解读(一) Protobuf详解教程

    前言:说到JSON可能大家很熟悉,是目前应用最广泛的一种序列化格式,它使用起来简单方便,而且拥有超高的可读性.但是在越来越多的应用场景里,JSON冗长的缺点导致它并不是一种最优的选择. 一.常用序列化 ...

  9. 如何恢复Initial commit之前的源文件

    在github新建了一个空的库,然后到本地文件夹下,git init了一下,将remote和本地的关联起来了,然后git pull了一下,本地的项目源码全没了,用以下命令可以帮你恢复 git refl ...

  10. jQuery 效果 – 停止动画

    jQuery stop() 方法用于在动画或效果完成前对它们进行停止. 点击这里,向上/向下滑动面板 实例 jQuery stop() 滑动 演示 jQuery stop() 方法. jQuery s ...