03 RadioButton 单选按钮
>概念:从多个互斥选项中选择一个 如果是选项全部展开 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 单选按钮的更多相关文章
- [tkinter]Radiobutton单选按钮的使用
首先因为单选按钮有一个特性(一个被选中后,自动清除其它按钮的选中状态) 所以使用方式也有点不同 错误示例 from tkinter import * root = Tk() r1 = Radiobut ...
- android.widget.RadioButton 单选按钮(转)
大家好,我们今天这一节要介绍的是RadioGroup 的组事件.RadioGroup 可将各自不同的RadioButton ,设限于同一个Radio 按钮组,同一个RadioGroup 组里的按钮,只 ...
- 控件_RadioGroup&&RadioButton(单选按钮)和Toast
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...
- JavaScript/JQuery radioButton(单选按钮)练习20190409
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- RadioButton单选按钮的使用
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { Initialize ...
- 03一些View总结
第三天 一 TextView 父类 : View >概念:文本控件 :文本内容的显示 默认配置不可编辑 子类EditText可以编辑 >属性: ...
- [ PyQt入门教程 ] PyQt5基本控件使用:单选按钮、复选框、下拉框
本文主要介绍PyQt5界面最基本使用的单选按钮.复选框.下拉框三种控件的使用方法进行介绍. 1.RadioButton单选按钮/CheckBox复选框.需要知道如何判断单选按钮是否被选中. 2.Com ...
- Android RadioButton控件
RadioButton 单选按钮 常用属性: text 文本 checked=“true” 默认选中 一组互斥的单选按钮要放在RadioGroup中.RadioGroup常用属性: orienta ...
- Android Studio 之 RadioButton
•任务 如何通过 RadioButton 实现如图所示的界面? •基本用法 RadioButton 单选按钮,就是只能够选中一个,所以我们需要把 RadioButton 放到 RadioGroup 按 ...
随机推荐
- UDA机器学习基础—误差原因
1.模型误差产生的原因 (1)模型无法表示基本数据的复杂度,而造成偏差. (2)因模型对训练它所用到的数据过度敏感造成的方差. 2.由偏差造成的误差--准确率和欠拟合 有足够数据表示模型,但是由于模型 ...
- Android智能手机中各种音频场景下的audio data path
上一篇文章(Android智能手机上的音频浅析)说本篇将详细讲解Android智能手机中各种音频场景下的音频数据流向,现在我们就开始.智能手机中音频的主要场景有音频播放.音频录制.语音通信等.不同场景 ...
- Axis2 webservice入门--Webservice的发布与调用
一.Webservice发布 参考 http://www.cnblogs.com/demingblog/p/3263576.html 二.webservice 调用 部分参考:http://www.c ...
- JavaScript反调试技巧
一.函数重定义 这是一种最基本也是最常用的代码反调试技术了.在JavaScript中,我们可以对用于收集信息的函数进行重定义.比如说,console.log()函数可以用来收集函数和变量等信息,并将其 ...
- Java获取随机数的3种方法
最小值---最大值(整数)的随机数 方法1 (数据类型)(最小值+Math.random()*(最大值-最小值+1)) 例: (int)(1+Math.random()*(10-1+1)) / ...
- js遍历 for-of
for-of遍历 entries() 返回一个遍历器对象,用来遍历[键名, 键值]组成的数组.对于数组,键名就是索引值:对于 Set,键名与键值相同.Map 结构的 Iterator 接口,默认就是调 ...
- vue mint-ui 实现省市区街道4级联动(仿淘宝京东收货地址4级联动)
demo及源码地址 https://github.com/artiely/citypicker 先去下载一个“省份.城市.区县.乡镇” 四级联动数据,然后 引入 import { Picker } f ...
- 如何去掉修改Joomla、joomlart及其模版版权、标志、图标的方法
Joomla是遵循GNU通用公共授权(GPL)的自由软件,我们虽然不推荐将Joomla的所有版权删除,但有些必要的信息还是需要修改的,下面以JoomlArt.com 的JA_teline_iii_v2 ...
- Git幕后的“故事”
因为做操作系统实验的原因,所以通读了一遍<Understanding git conceptually>,觉得确实不错,于是就简单地记录一下.有的地方理解的还不是很深,可能不够准确,等抽时 ...
- 20160225.CCPP体系详解(0035天)
程序片段(01):CircleList.h+CircleList.c+main.c 内容概要:环形链表 ///CircleList.h #pragma once #include <stdio. ...