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 按 ...
随机推荐
- Angular中 build的时候遇到的错误--There are multiple modules with names that only differ in casing
今天早上遇到一个Angular的编译的时候的错误 具体信息: There are multiple modules with names that only differ in casing.This ...
- python中没有字符(char)这一基本数据类型
感觉受C语言的影响太大了,一开始以为python中也会有字符这一基本数据类型,后来遇到了很多问题,这才发现python中压根没有这一数据类型( ╯□╰ ). 吐槽一下:感觉python还真是'够简单啊 ...
- jvm(二):内存管理
jvm内存区域总体分为5大块:方法区,java堆,虚拟机栈,本地方法栈,程序计数器,按照线程来分的话又分为线程共享区和线程独占区 程序计数器: a.程序计数器是一块较小的内存空间,可以看做是当前线程所 ...
- css3中-moz、-ms、-webkit各什么意思
1.-moz代表firefox浏览器私有属性 2.-ms代表ie浏览器私有属性 3.-webkit代表safari.chrome私有属性 这些是为了兼容老版本的写法,比较新版本的浏览器都支持直接写:b ...
- RESTful 最佳实战
在GitHub上看到一本不错的关于REST实战的书,很高兴分享阅读笔记.[下载地址] 一.什么是REST(WHAT) REST架构描述了六种约束.(统一接口.无状态.可缓存.CS架构.分层系统.按需编 ...
- JS 中判断空值 undefined 和 null
1.JS 中如何判断 undefined JavaScript 中有两个特殊数据类型:undefined 和 null,下节介绍了 null 的判断,下面谈谈 undefined 的判断. 以下是不正 ...
- 使用CSS让多出来的字变为省略号
<style> .text1 { width:200px; overflow:hidden; text-overflow:ellipsis; -o-text-overflow:ellips ...
- 利用create-react-app结合react-redux、react-router4构建单页应用
1.创建项目: a.全局安装create-react-app: npm install create-react-app -g b.执行create-react-app my-projectN ...
- ubuntu批量更改文件权限
重装系统之后,把文件从windows分区拷到linux分区发现所有文件的权限全是777,在终端下看到所有文件的颜色都很刺眼,文件有很多,一个一个改不现实,所以写了一段python脚本批量更改文件权限. ...
- Codeforces Round #396(Div. 2) A. Mahmoud and Longest Uncommon Subsequence
[题意概述] 找两个字符串的最长不公共子串. [题目分析] 两个字符串的最长不公共子串就应该是其中一个字符串本身,那么判断两个字符串是否相等,如果相等,那么肯定没有公共子串,输出"-1&qu ...