<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
tools:context="com.example.dell.test5.UiActivity1"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请选择Android的开发语言"/>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/rg"> <RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C++"
android:id="@+id/rb1"
android:layout_marginRight="30dp"
/> <RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C"
android:id="@+id/rb2"
android:layout_marginRight="30dp"
android:checked="true"/> <RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Java"
android:id="@+id/rb3"
android:layout_marginRight="30dp"/> <RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C#"
android:id="@+id/rb4" /> </RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请选择字体效果"/> <CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="宋体"
android:id="@+id/cb_st" /> <CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="加粗"
android:id="@+id/cb_jc" /> <CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="斜体"
android:id="@+id/cb_xt" /> <CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下划线"
android:id="@+id/cb_xhx" /> </LinearLayout>
package com.example.dell.test5;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast; public class UiActivity1 extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ui1); RadioGroup radioGroup = (RadioGroup)findViewById(R.id.rg); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override
public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == R.id.rb3) { Toast.makeText(UiActivity1.this, "选对了", Toast.LENGTH_SHORT).show();
} RadioButton rb = (RadioButton) findViewById(checkedId); Toast.makeText(UiActivity1.this, rb.getText(), Toast.LENGTH_LONG).show();
}
}); CheckBox cb_st = (CheckBox)findViewById(R.id.cb_st); cb_st.setOnCheckedChangeListener(new CBOnCheckedChangeListenner()); CheckBox cb_jc = (CheckBox)findViewById(R.id.cb_jc); cb_jc.setOnCheckedChangeListener(new CBOnCheckedChangeListenner()); CheckBox cb_xt = (CheckBox)findViewById(R.id.cb_xt); cb_xt.setOnCheckedChangeListener(new CBOnCheckedChangeListenner()); CheckBox cb_xhx = (CheckBox)findViewById(R.id.cb_xhx); cb_xhx.setOnCheckedChangeListener(new CBOnCheckedChangeListenner()); } private class CBOnCheckedChangeListenner implements CompoundButton.OnCheckedChangeListener {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
CheckBox cb = (CheckBox)buttonView; if(isChecked)
{
Toast.makeText(UiActivity1.this, "选中了" + cb.getText(), Toast.LENGTH_SHORT).show(); }
else
{ Toast.makeText(UiActivity1.this, "取消了" + cb.getText(), Toast.LENGTH_SHORT).show();
} }
} }

android单选框和复选框(练习)的更多相关文章

  1. CSS学习笔记三:自定义单选框,复选框,开关

    一点一点学习CCS,这次学习了如何自定义单选框,复选框以及开关. 一.单选框 1.先写好body里面的样式,先写几个框 <body> <div class="radio-1 ...

  2. 自动化测试-15.selenium单选框与复选框状态判断

    本篇主要介绍单选框和复选框的操作 一.认识单选框和复选框 1.先认清楚单选框和复选框长什么样 2.各位小伙伴看清楚哦,上面的单选框是圆的:下图复选框是方的,这个是业界的标准,要是开发小伙伴把图标弄错了 ...

  3. 2.12 单选框和复选框(radiobox、checkbox)

    2.12 单选框和复选框(radiobox.checkbox) 本篇主要介绍单选框和复选框的操作一.认识单选框和复选框    1.先认清楚单选框和复选框长什么样 2.各位小伙伴看清楚哦,上面的单选框是 ...

  4. Selenium2学习(十五)-- 单选框和复选框(radiobox、checkbox)

    本篇主要介绍单选框和复选框的操作 一.认识单选框和复选框 1.先认清楚单选框和复选框长什么样 2.各位小伙伴看清楚哦,上面的单选框是圆的:下图复选框是方的,这个是业界的标准,要是开发小伙伴把图标弄错了 ...

  5. 微信小程序-修改单选框和复选框大小的方法

    方法有两种: 一:采用css的zoom属性 zoom缩放会将元素保持在左上角,并且会有毛边,可能会稍稍改变元素原来的形状. 二:采用css3的transform:scale属性 zoom缩放会将元素保 ...

  6. HTML--使用单选框、复选框,让用户选择

    在使用表单设计调查表时,为了减少用户的操作,使用选择框是一个好主意,html中有两种选择框,即单选框和复选框,两者的区别是单选框中的选项用户只能选择一项,而复选框中用户可以任意选择多项,甚至全选.请看 ...

  7. Selenium3+python自动化 单选框和复选框

    一.认识单选框和复选框 1.先认清楚单选框和复选框长什么样 2.各位小伙伴看清楚哦,上面的单选框是圆的:下图复选框是方的,这个是业界的标准,要是开发小伙伴把图标弄错了,可以先抽他了. 二.radio和 ...

  8. jQuery获取单选框(复选框)选中的状态

    jQuery 获取单选框(复选框)选中的状态 <input type="checkbox" name="" id="choose"/& ...

  9. vue.js实现单选框、复选框和下拉框

    Vue.js可以很方便的实现数据双向绑定,所以在处理表单,人机交互方面具有很大的优势.下边以单选框.复选框和下拉框为例介绍他们在HTML和Vue.js中的具体实现方式. 一.单选框   在传统的HTM ...

  10. Selenium+java - 单选框及复选框处理

    一.什么是单选框.复选框? 二.被测页面html源代码 CheckBoxRadioDemo.html <!DOCTYPE html> <html lang="en" ...

随机推荐

  1. PHP排序函数

    /** * 对查询结果集进行排序 * http://www.onethink.cn * /Application/Common/Common/function.php * * @access publ ...

  2. RCNN--对象检测的又一伟大跨越

    最近在实验室和师兄师姐在做有关RCNN的研究,发现这里面坑很深呀,在网上找了一个大牛的博客,准备下来继追OPENCV同时,再来追一个RCNN的学习笔记的博文,博文地址如下:http://blog.cs ...

  3. POJ - 1666 Candy Sharing Game

    这道题只要英语单词都认得,阅读没有问题,就做得出来. POJ - 1666 Candy Sharing Game Time Limit: 1000MS Memory Limit: 10000KB 64 ...

  4. JS中Float类型加减乘除 修复

    MXS&Vincene  ─╄OvЁ  &0000027─╄OvЁ  MXS&Vincene MXS&Vincene  ─╄OvЁ:今天很残酷,明天更残酷,后天很美好, ...

  5. Couchbase学习记录

    Couchbase是membase的升级版,membase与memcache是同一家公司出的,Couchbase包含了memcache的功能. 从其官网上下载最新的版本安装即可.安装成功后会弹出设置页 ...

  6. apache+php+mysql的配置(转载)

    windows: 按http://jingyan.baidu.com/article/fcb5aff797ec41edaa4a71c4.html的安装 按http://www.jb51.net/art ...

  7. 阿里云OneinStack数据库相关

    阿里云OneinStack数据库相关必须进入oneinstack目录下执行相关命令 ===================================源码安装目录: Nginx:/usr/loca ...

  8. 今日随笔:scrollTop与overflow

    今天想写一个页面一加载滚动条就自动滚到底部的效果,结果在IE上实现成功了,chrome上完全没反应,最后测试了一下,居然是因为css文件中,html,body都写了overflow:auto这一语句, ...

  9. c/s 与b/s构架

    C/S架构是一种比较早的软件架构,主要应用于局域网内.在这之前经历了集中计算模式,随着计算机网络的进步与发展,尤其是可视化工具的应用,出现过两层C/S和三层C/S架构,不过一直很流行也比较经典的是我们 ...

  10. laravel框架总结(五) -- 服务提供者(提及契约Contracts)

    首先理解两个概念 1.契约:一组定义了框架核心服务的接口 2.服务提供者:所有 Laravel 应用程序启动的中心所在. 包括你自己的应用程序,以及所有的 Laravel 核心服务,都是通过服务提供者 ...