activity_ui1.xml

<?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:padding="10dp"
android:orientation="vertical"
tools:context="com.hanqi.application3.UIActivity1"
android:weightSum="1"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请选择Android的开发语言是什么"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/rb"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C++"
android:id="@+id/rb1"
android:layout_marginRight="30dp"
android:checked="true"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C"
android:id="@+id/rb2"
android:layout_marginRight="30dp"
/>
<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"
android:layout_marginRight="30dp"
/> </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"
android:checked="true"
/>
<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>
UIActivity1.java
package com.hanqi.application3;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast; import static android.widget.CompoundButton.*; public class UIActivity1 extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ui1); RadioGroup radioGroup = (RadioGroup)findViewById(R.id.rb); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, @IdRes 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_SHORT).show();
} }); CheckBox cb_st= (CheckBox)findViewById(R.id.cb_st);
cb_st.setOnCheckedChangeListener(new CBOnCheckChangeListenter());
CheckBox cb_xt= (CheckBox)findViewById(R.id.cb_xt);
cb_xt.setOnCheckedChangeListener(new CBOnCheckChangeListenter());
CheckBox cb_jc= (CheckBox)findViewById(R.id.cb_jc);
cb_jc.setOnCheckedChangeListener(new CBOnCheckChangeListenter());
CheckBox cb_xhx= (CheckBox)findViewById(R.id.cb_xhx);
cb_xhx.setOnCheckedChangeListener(new CBOnCheckChangeListenter());
} private class CBOnCheckChangeListenter implements OnCheckedChangeListener
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { CheckBox cb = (CheckBox)buttonView;
if (isChecked) {
Toast.makeText(UIActivity1.this, "选中了", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(UIActivity1.this, "取消了", Toast.LENGTH_SHORT).show();
}
}
}
}

andorid 单选与复选的更多相关文章

  1. 关于通过jq /js 实现验证单选框 复选框是否都有被选中

    今天项目中遇到一个问题 就是要实现,单选框,复选框 同时都被选中才能进行下一步的问题,开始用js原生来写 怎么写都觉得不合适,通过for循环得出 复选框被选中的,在通过for循环得出单选框被选中的,问 ...

  2. Webfrom 生成流水号 组合查询 Repeater中单选与复选控件的使用 JS实战应用

                                             Default.aspx 网页界面 <%@ Page Language="C#" AutoE ...

  3. Webfrom 生成流水号 组合查询 Repeater中单选与复选控件的使用 JS实战应用

                                             Default.aspx 网页界面 <%@ Page Language="C#" AutoE ...

  4. php一些单选、复选框的默认选择方法(示例)

    转载 http://www.php.cn/php-weizijiaocheng-360029.html 一. radio和checkbox及php select默认选择的实现代码 1.radio单选框 ...

  5. Python3+Selenium3+webdriver学习笔记8(单选、复选框、弹窗处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记8(单选.复选框.弹窗处理)''' from selenium ...

  6. iCheck获取单选和复选框的值和文本

    //获取单选和复选框的值//parameters.type:"radio","checkbox"//parameters.name:input-name//pa ...

  7. [Swift通天遁地]二、表格表单-(17)制作在表单左侧添加单选和复选组件的表单行

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  8. 在微信框架模块中,基于Vue&Element前端,通过动态构建投票选项,实现单选、复选的投票操作

    最近把微信框架的前端改造一下,在原来基于Bootstrap框架基础上的微信后台管理,增加一套Vue&Element的前端,毕竟Vue的双向绑定开发起来也还是很方便的,而且Element本身也提 ...

  9. jquery模拟下拉框单选框复选Select,Checkbox,Radio

    在项目中,你会发现设计稿中常常会有单选框,复选框,但都不是系统默认的样式,这就可以用jquery来模拟它们:如图所示,实现它们所需要的代码如下: 首先需要引入的代码: <link rel=&qu ...

随机推荐

  1. thymeleaf 字符串的拼接

  2. 关于xml中自动提示功能的设置

    我们在编写xml文件时如果有自动提示功能,将会事半功倍,下面我就怎么设置xml进行说明: 在xml文件的开始几行一般有编写xml文件的语法要求;如 <!DOCTYPE hibernate-con ...

  3. Oracle 查询表的字段注释

    SELECT TABLE_NAME, COLUMN_NAME, COMMENTSFROM USER_COL_COMMENTSWHERE TABLE_NAME = 'TB_MENU';

  4. ssh架构之hibernate(三)关系映射

    1.单向多对一 1.映射文件配置 2.model: 测试 1.查询测试 执行顺序,先查询多方,在查询一方,一方采用延迟加载 注意:如果不使用一方的数据,就关闭session,报错,同延迟加载中的报错类 ...

  5. Java读取.properties配置文件并连接数据库

    1.读取配置文件 //Properties集合 流对象读取键值对 public static void getNum() throws Exception { Properties p=new Pro ...

  6. tomcat部署war包

    部署步骤 1.下载tomcat 直接在网上下载即可,随便把包下到一个地方 下面文中的xxx均代表tomcat的安装目录   2.将java工程导出war包 在intellij idea的执行左侧选中t ...

  7. 调试JS代码的神器

    1.火狐浏览器的 “Web开发者” 可以打断点,实时查看当前值 2.谷歌浏览器的“开发者工具” 可以打断点,实时查看当前值

  8. 侯捷STL课程及源码剖析学习2: allocator

    以STL 的运用角度而言,空间配置器是最不需要介绍的东西,它总是隐藏在一切组件(更具体地说是指容器,container)的背后,默默工作默默付出. 一.分配器测试 测试代码 #include < ...

  9. laravel框架目录结构详解

  10. TOJ3097: 单词后缀 (字典树 or map瞎搞)

    传送门 (<---可以点击的~) 时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte 描述 有些英语单词后缀都是一样的,现在我们需要从给定的一堆单词里 ...