Android——RadioGroup和CheckBox
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:orientation="vertical"
tools:context="com.example.chenshuai.test322.UIActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请选择Android的开发语言是什么?"
android:padding="10dp"/> <RadioGroup
android:layout_width="match_parent"
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"
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"
/>
</RadioGroup> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请选择字体效果:"
android:id="@+id/ziti"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="宋体"
android:checked="true"
android:id="@+id/cb_song"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="加粗"
android:id="@+id/cb_cu"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="斜体"
android:id="@+id/cb_xie"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下划线"
android:id="@+id/cb_xia"/> </LinearLayout>
java
package com.example.chenshuai.test322; 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 UIActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ui); RadioGroup radioGroup = (RadioGroup)findViewById(R.id.rg); //radiogroup的监听事件 匿名内部类
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override
public void onCheckedChanged(RadioGroup group, int checkedId) { RadioButton rb = (RadioButton) findViewById(checkedId); if (checkedId == R.id.rb3) {
Toast.makeText(UIActivity.this, "选对了", Toast.LENGTH_LONG).show();
}
Toast.makeText(UIActivity.this, rb.getText(), Toast.LENGTH_LONG).show(); }
});
CheckBox cb_song = (CheckBox)findViewById(R.id.cb_song);
cb_song.setOnCheckedChangeListener(new cboncheckedchangelistener()); CheckBox cb_cu = (CheckBox)findViewById(R.id.cb_cu);
cb_cu.setOnCheckedChangeListener(new cboncheckedchangelistener()); CheckBox cb_xia = (CheckBox)findViewById(R.id.cb_xia);
cb_xia.setOnCheckedChangeListener(new cboncheckedchangelistener()); CheckBox cb_xie = (CheckBox)findViewById(R.id.cb_xie);
cb_xie.setOnCheckedChangeListener(new cboncheckedchangelistener()); } //checkbox的监听事件 内部类
private class cboncheckedchangelistener implements CompoundButton.OnCheckedChangeListener
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { CheckBox cb = (CheckBox)buttonView; if (isChecked)
{
Toast.makeText(UIActivity.this, "选中了"+cb.getText(), Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(UIActivity.this, "取消选中了"+cb.getText(), Toast.LENGTH_SHORT).show();
} }
}
}

Android——RadioGroup和CheckBox的更多相关文章
- Android UI系列-----CheckBox和RadioButton(1)
主要记录一下CheckBox多选框和RadioGroup.RadioButton单选框的设置以及注册监听器 1.CheckBox 布局文件: <LinearLayout xmlns:androi ...
- Android ExpandableListView 带有Checkbox的简单应用
expandablelistview2_groups.xml <?xml version="1.0" encoding="utf-8"?> < ...
- android listview 使用checkbox问题
在android中使用listview时需要了解listview加载数据的原理,为了避免listview由于列表项过多每次需要进行new造成性能低下的问题,android中的listview使用了控件 ...
- [转]Android中自定义checkbox样式
android中自定义checkbox的图片和大小 其实很简单,分三步: 1.在drawable中创建文件checkbox_selector.xml: <?xml version=" ...
- Android ListView带CheckBox实现单选
第1种方法: 首先是我们的bean: public class Bean { private boolean isChecked; private String msg = "这是一条测试数 ...
- Android Studio 之 CheckBox
•任务 •基本用法 CheckBox,复选框,即可以同时选中多个选项. 从网上找了三个图标,分别命名为 apple.jpg , banana.jpg , oranges.jpg 放置在了 drawab ...
- Android RadioGroup和RadioButton详解
实现RadioButton由两部分组成,也就是RadioButton和RadioGroup配合使用.RadioGroup是单选组合框,可以容纳多个RadioButton的容器.在没有RadioGrou ...
- Android学习笔记——CheckBox
该工程的功能实现在一个activity中显示一个单选框和一个多选框 以下代码是MainActivity.java文件中的代码 package com.example.checkbox; import ...
- Android RadioGroup 及资源文件 & selector
RadioGroup :单选组 RadioButton :单选按钮 RadioButton和CheckBox的区别: 1.单个RadioButton在选中后,通过点击无法变为未选中 单 ...
随机推荐
- [ubuntu]为ubuntu设立“任务管理器”的组合键
在windows下面,我们可以方便的使用ctrl+alt+delete调出任务管理器,那么在ubuntu下面如何实现呢?这里我们介绍两种方法:1.在终端下运行: 代码:gconf-editor 找到: ...
- 马老师 linux必备web服务入门及高级进阶
http://edu.51cto.com/course/course_id-866.html HTTP: HyperText Transfer Protocol 超文本传输协议 超链接: Web: h ...
- POJ 3691 DNA Sequence (AC自动机 + 矩阵 有bug,待修改)
DNA Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9889 Accepted: 3712 Desc ...
- 数据库分析函数 ROW_NUMBER() rank() dense_rank() 的区别 first_value(D) , last_value(D)
直接上图 select * from tab select B,ROW_NUMBER()over(order by B) from tab 当碰到相同数据时,排名按照记录集中记录的顺序依次递增. 遇 ...
- python学习笔记013——模块
1 模块module 1.1 模块是什么 模块是包含一系列的变量,函数,类等程序组 模块通常是一个文件,以.py结尾 1.2 模块的作用 1. 让一些相关的函数,变量,类等有逻辑的组织在一起,使逻辑更 ...
- RAC安装重新运行root.sh
rac1执行root.sh成功,rac2执行失败. 在重新执行root.sh前,在rac2上把crs等配置信息删除: # /u01/app//grid/crs/install/rootcrs.pl - ...
- Sublime Text 无法使用Package Control或插件安装失败的解决方法
Sublime Text用了一年多了,公司搬家近期突然发现Package Control无法安装新插件了.尽管不影响原有功能的使用.还是要解决它.因为本人用Windows系统,仅仅讨论Windosw下 ...
- [转]HSPICE软件的应用及常见问题解决
HSPICE常用分析类型 直流分析(DC Analysis)( 参见HSPICE User’s Manual (1)3-4 ) 常用命令: .OP 直流工作点分析 .NODESET 节点设置 .SEN ...
- 办公技巧:局域网内设置固定ip
第一步:查看自己现在的网络配置 打开命令行,输入:ipconfig /all 第二步:打开控制面板 - 网络配置 根据CMD命令的ipconfig信息对号入座填入即可. 然后,重启一下WIFI即可. ...
- [na]windows2008-AD域的安装
AD域的安装 初始化设置,改计算机名字dcserver,改静态ip,改dns指向自己. dcpromo,执行后自动装了dns 安装完后检查 1.本地用户没了 2,dns指向自己 3,dns记录是否齐全 ...