>概念:从多个互斥选项中选择一个  如果是选项全部展开  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. C++变量和基本类型——2.3.1引用

    引用:为对象起了另外一个名字,通常将申明符写成&d的形式来定义引用类型,其中d是申明的变量名: int ival =1024; int &refVal=ival 一般在初始化变量时,初 ...

  2. Java并发编程之并发工具类

    CountDownLatch CountDownLatch可以用于一个或多个线程等待其他线程完成操作. 示例代码 private static CountDownLatch c = new Count ...

  3. curl_multi实现并发

    普通请求 curl_normal.php <?php $srart_time = microtime(TRUE); $chArr=[]; //创建多个cURL资源 for($i=0; $i< ...

  4. CSS :focus 选择器

    :focus 选择器用于选取获得焦点的元素. <!DOCTYPE html> <html> <head> <style> input:focus { b ...

  5. session.save()返回值问题

    正常都应该返回插入的主键 但是 如果你用sessionFactory来写就一定返回0 先科普下持久化数据库的三个状态方便下面理解 一次会话状态中,持久化对象经历以下三种状态:1 transient:对 ...

  6. Java阻塞队列的实现

    阻塞队列与普通队列的区别在于,当队列是空的时,从队列中获取元素的操作将会被阻塞,或者当队列是满时,往队列里添加元素的操作会被阻塞.试图从空的阻塞队列中获取元素的线程将会被阻塞,直到其他的线程往空的队列 ...

  7. JavaScript正则表达式模式匹配(4)——使用exec返回数组、捕获性分组和非捕获性分组、嵌套分组

    使用exec返回数组 var pattern=/^[a-z]+\s[0-9]{4}$/; var str='google 2012'; alert(pattern.exec(str)); //返回一个 ...

  8. kafka Centos7.2 单机集群搭建

    前提是已经安装好了zk集群 1.下载  kafka_2.11-1.0.0.tgz  下载网址 http://kafka.apache.org/documentation.html 2.解压  tar ...

  9. Django项目实战之用户头像上传与访问

      1 将文件保存到服务器本地 upload.html <!DOCTYPE html> <html lang="en"> <head> < ...

  10. flowable设计器插件安装

    原文地址:http://www.shareniu.com/ 工欲善其事必先利其器,要想使用flowable,必须搭建一套环境,本文以Eclipse中安装flowable插件为例详细说明整个安装过程. ...