main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<CheckBox
android:id="@+id/eatId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="吃饭" />
<CheckBox
android:id="@+id/sleepId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="睡觉" />
<CheckBox
android:id="@+id/playDotaId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="打dota" />
<CheckBox
android:id="@+id/allCheckId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="全选" />
</LinearLayout>

MainActivity.java:

package com.example.allchecked;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener; public class MainActivity extends Activity {
private CheckBox eatBox;
private CheckBox sleepBox;
private CheckBox playDotaBox;
private CheckBox allCheckBox; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
eatBox = (CheckBox)findViewById(R.id.eatId);
sleepBox = (CheckBox)findViewById(R.id.sleepId);
playDotaBox = (CheckBox)findViewById(R.id.playDotaId);
allCheckBox = (CheckBox)findViewById(R.id.allCheckId); AllCheckListener allCheckListener = new AllCheckListener();
allCheckBox.setOnCheckedChangeListener(allCheckListener); CheckBoxListener listener = new CheckBoxListener();
eatBox.setOnCheckedChangeListener(listener);
sleepBox.setOnCheckedChangeListener(listener);
playDotaBox.setOnCheckedChangeListener(listener); /* OnBoxClickListener clicklistener = new OnBoxClickListener();
eatBox.setOnClickListener(clicklistener);
sleepBox.setOnClickListener(clicklistener);
playDotaBox.setOnClickListener(clicklistener);
*/
} /* class OnBoxClickListener implements OnClickListener{ @Override
public void onClick(View view) {
// TODO Auto-generated method stub
CheckBox box = (CheckBox)view;
if(box.getId() == R.id.eatId){
System.out.println("eatBox");
}
else if(box.getId() == R.id.sleepId){
System.out.println("sleepBox");
}
else{
System.out.println("dotaBox");
}
if(box.isChecked()){
System.out.println("checked");
}
else{
System.out.println("unchecked");
}
}
}*/ public class CheckBoxListener implements OnCheckedChangeListener{ @Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
if(buttonView.getId() == R.id.eatId){
System.out.println("eatBox");
}
else if(buttonView.getId() == R.id.sleepId){
System.out.println("sleepBox");
}
else{
System.out.println("dotaBox");
}
if(isChecked){
System.out.println("checked");
}
else{
System.out.println("unchecked");
}
} } public class AllCheckListener implements OnCheckedChangeListener{ @Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
eatBox.setChecked(isChecked);
sleepBox.setChecked(isChecked);
playDotaBox.setChecked(isChecked);
} } }

全选按钮的功能还不是很完善,选中上面三个所有,全选按钮不会自动被选中;同时点击全选之后,点击上面某一个不再选中,全选不会自动取消选中。

多选按钮CheckBox的更多相关文章

  1. JQuery 多选按钮checkbox

    JQuery 多选按钮checkbox 在需要全选和选择部分的时候我们就需要多选在这里主要介绍了具体的实现 JQuery $(function () { //全选或全不选 $("#allbo ...

  2. cocos2d-x JS 复选按钮checkBox的单选与多选

    var HZ_createRoom = jx.BaseView.extend({//红中麻将 ctor : function() { this._super(); this.addLayout(res ...

  3. zepto全选按钮之全选会根据按钮是否被全部选中更改状态

    在做手机端二次开发购物车的时候,发现zepto全选,没找到,或者功能不是自己想要的 后来做好,分享给需要的人 //全选或多选处理      var CheckAll = $('#items_check ...

  4. Android开发 ---基本UI组件2:图像按钮、单选按钮监听、多选按钮监听、开关

    Android开发 ---基本UI组件2 1.activity_main.xml 描述: 定义一个按钮 <?xml version="1.0" encoding=" ...

  5. 『心善渊』Selenium3.0基础 — 14、Selenium对单选和多选按钮的操作

    目录 1.页面中的单选按钮和多选按钮 2.判断按钮是否选中is_selected() 3.单选按钮的操作 4.多选按钮的操作 5.选择部分多选按钮的操作 1.页面中的单选按钮和多选按钮 页面中的单选按 ...

  6. checkbox做全选按钮

    1.先写一个html页面,里面写一个全选按钮和几个复选框,实现下面2个要求 (1)点击全选按钮选中时,所有的复选框选中. (2)点击全选按钮取消选中时,所有复选框取消选中. <input typ ...

  7. js做全选,用一个checkbox复选框做多个checkbox复选框的全选按钮,有一个复选框未被选择时,全选按钮的checked就为false

    用一个checkbox复选框做多个checkbox复选框的全选按钮,有一个复选框未被选择时,全选按钮的checked就为false,当所有checkbox都被选中时,全选按钮也被选中. 详解: 有两种 ...

  8. 安卓开发_复选按钮控件(CheckBox)的简单使用

    复选按钮 即可以选择若干个选项,与单选按钮不同的是,复选按钮的图标是方块,单选按钮是圆圈 复选按钮用CheckBox表示,CheckBox是Button的子类,支持使用Button的所有属性 一.由于 ...

  9. 微信小程序 修改(自定义) 单选/复选按钮样式 checkbox/radio样式自定义

    参考文章: 微信小程序 修改(自定义) 单选/复选按钮样式 checkbox/radio样式自定义

随机推荐

  1. vue 事件总线(bus)

    1.全局引入bus Vue.prototype.$bus = new.Vue() 2.组件间传值使用(在发送事件时接收组件会实时接收到, 可以用做兄弟组件间相互传值, 但页面跳转组件间有问题 通过$e ...

  2. maven工程引入外部jar包

    pom.xml: <dependency> <groupId>new</groupId> <artifactId>new</artifactId& ...

  3. 吴裕雄 Bootstrap 前端框架开发——简例

    <!DOCTYPE html> <html> <head> <title>Bootstrap 模板</title> <meta cha ...

  4. MySQL表结构导出Excel

    1. information_schema.COLUMNS表记录了所有库中所有表的字段信息 SELECT COLUMN_NAME 字段名称, COLUMN_TYPE 字段类型, COLUMN_DEFA ...

  5. How2J学习java-1、环境配置

    JDK环境变量配置分下载,配置,验证三个步骤. 一.首先需要到JDK下载网站下载所需的JDK版本可根据更新来定.主流的开发工具Idear下载. 1.首先看配置成功后的效果 点WIN键->运行(或 ...

  6. 操作系统OS - Zip Bomb

    42.zip - A 42 kb zip file that contains 4.5 Petabytes of uncompressed data.

  7. CSS - 精灵Sprite

    1. CSS精灵是一种处理网页背景图像的方式. 2. 它将一个页面涉及到的所有零星背景图像都集中到一张大图中去,然后将大图应用于网页,这样,当用户访问该页面时,只需向服务发送一次请求,网页中的背景图像 ...

  8. UITextField的快速基本使用代码块

    概述 UITextField在界面中显示可编辑文本区域的对象. 您可以使用文本字段来使用屏幕键盘从用户收集基于文本的输入.键盘可以配置许多不同类型的输入,如纯文本,电子邮件,数字等等.文本字段使用目标 ...

  9. Win10中小娜无法搜索本地应用

    解决方案 1.win+X  -    Windows PowerShell(管理员) 2. 输入Get-AppXPackage -Name Microsoft.Windows.Cortana | Fo ...

  10. 微信小程序 列表倒计时

    最近要实现一个列表倒计时的功能,写了个demo 展示图 <view class="center colu"> <view class="time&quo ...