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 按 ...
随机推荐
- Mac下Git安装及配置
Mac下: 1.下载git版本并安装 运行终端 查看git版本: bogon:~ yan$ git --version git version 2.16.3 配置gitconfig文件 vim ~/. ...
- 【转载】 HTTP 中 GET 与 POST 的区别
HTTP 中 GET 与 POST 的区别 GET和POST是HTTP请求的两种基本方法,要说它们的区别,接触过WEB开发的人都能说出一二. 最直观的区别就是GET把参数包含在URL中,POST通 ...
- 非Unicode编码的软件如何在Windows系统上运行
我们常常会遇到这样一种情况:点开某些日文软件(我不会说就是galgame( ╯□╰ ))会出现乱码或者直接无法运行. 出现乱码的原因很简单:编码与译码的方式不一致!!!!!!!!!!! 首先大家需要知 ...
- C语言第三次程序设计作业
(一)改错题 计算f(x)的值:输入实数x,计算并输出下列分段函数f(x)的值,输出时保留1位小数. 1)源程序(有错误的程序) #include <stdio.h> int main(v ...
- 解决nodejs中json序列化时Date类型默认为UTC格式
在nodejs中,json序列化时Date类型时,默认转为UTC格式. 如下图 上面只是一个例子,下面我用一个更具体化的例子来展示一个这个情况,我们在开发WEB项目中,经常用到Express组件, 我 ...
- 阿里技术一面,Java研发岗
之前过了个简单的简历面,过了几天后没打来以为凉了,然后昨晚又接到了电话,括号内容是回答说的,理解有限,不一定都对,欢迎纠正-加油每一个牛友们! 阿里一面: 1.学过哪些技术知识呢? 2.说说接口和抽象 ...
- button点击切换,获取按钮ID
<!DOCTYPE html> <html> <head lang="zh-CN"> <meta charset="UTF-8& ...
- 点(x1, y1)关于点(x0, y0)逆时针旋转a度后的坐标求解
问题描述: 求点(x1, y1)关于点(x0, y0)逆时针旋转a度后的坐标 思路: 1.首先可以将问题简化,先算点(x1, y1)关于源点逆时针旋转a度后的坐标,求出之后加上x0,y0即可. 2.关 ...
- RESTful Console Application
RESTful Console Application Introduction Inspirited by RESTFul architecture, A console application t ...
- Django笔记--视图
URLconf 在settings.py文件中通过ROOT_URLCONF指定根级url的配置 urlpatterns是一个url()实例的列表 一个url()对象包括: 正则表达式 视图函数 名称n ...