一、

1.checkbox_layout.xml

 <?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" >
<CheckBox
android:id="@+id/checkAllId"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="全选"/>
<CheckBox
android:id="@+id/eatId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000"
android:textSize="50dp"
android:text="吃饭"/>
<CheckBox
android:id="@+id/sleepId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#0000ff"
android:textSize="50sp"
android:text="睡觉"/> </LinearLayout>

2.MainActivity.java

 @SuppressLint("NewApi")
public class MainActivity extends ActionBarActivity { private TextView textView;
private Button button;
int count = 0;
//CheckBox
private CheckBox eateBox;
private CheckBox sleepBox;
private CheckBox checkAll; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.checkbox_layout); //checkbox
eateBox = (CheckBox) findViewById(R.id.eatId);
sleepBox = (CheckBox) findViewById(R.id.sleepId);
checkAll = (CheckBox) findViewById(R.id.checkAllId);
OnBoxChickListener boxListener = new OnBoxChickListener();
// eateBox.setOnClickListener(boxListener);
// sleepBox.setOnClickListener(boxListener);
OnBoxChangeListener changeListener = new OnBoxChangeListener();
eateBox.setOnCheckedChangeListener(changeListener);
sleepBox.setOnCheckedChangeListener(changeListener);
checkAll.setOnCheckedChangeListener(changeListener); // setContentView(R.layout.dpsp_layout);
// setContentView(R.layout.activity_main);
//setContentView(R.layout.first_layout); /*TextView textView = (TextView) findViewById(R.id.textView);
textView.setText("Hello View");
textView.setBackgroundColor(Color.CYAN); button = (Button) findViewById(R.id.button);
ButtonListener buttonListener = new ButtonListener();
button.setOnClickListener(buttonListener);*/ } class OnBoxChickListener implements OnClickListener { @Override
public void onClick(View v) {
System.out.println(v.getId());
CheckBox box = (CheckBox) v;
System.out.println(box.isChecked());
System.out.println("CheckBox is clicked");
} } class OnBoxChangeListener implements OnCheckedChangeListener { @Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if(R.id.eatId == buttonView.getId()) {
System.out.println("eatButton");
} else if(R.id.sleepId == buttonView.getId()) {
System.out.println("sleepButton");
} else if(R.id.checkAllId == buttonView.getId()) {
eateBox.setChecked(isChecked);
sleepBox.setChecked(isChecked);
}
System.out.println(isChecked ? "选中" : "取消");
} }

ANDROID_MARS学习笔记_S01_005CheckBox的更多相关文章

  1. ANDROID_MARS学习笔记_S01_012_RatingBar

    1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ...

  2. ANDROID_MARS学习笔记_S01_012_SeekBar

    1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ...

  3. ANDROID_MARS学习笔记_S01_011ProgressBar

    文档是这样来设置样式 <ProgressBar android:layout_width="wrap_content" android:layout_height=" ...

  4. ANDROID_MARS学习笔记_S01_010日期时间控件

    1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ...

  5. ANDROID_MARS学习笔记_S01_009Relative_LAYOUT例子

    1. <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android ...

  6. ANDROID_MARS学习笔记_S01_008Linear_layout例子

    1.netstone_layout.xml <?xml version="1.0" encoding="utf-8"?> <LinearLay ...

  7. ANDROID_MARS学习笔记_S01_007Linear_layout嵌套与layout_weight的设置

    一.介绍 二.1.linear_layout.xml <?xml version="1.0" encoding="utf-8"?> <Line ...

  8. ANDROID_MARS学习笔记_S01_006ImageView

    一.ImageView介绍 设置scalType Must be one of the following constant values. Constant Value Description ma ...

  9. ANDROID_MARS学习笔记_S01_004dpi、dp(dip)及计算

    一.dpi.dp介绍 sp会随着用户在手机中设置字体大小而改变,而dp不会 二.1.dpsp_layout.xml <?xml version="1.0" encoding= ...

随机推荐

  1. info sed 中文不完全文档

    快速指南: sed 的一般使用方法:sed -option 'adress|command' -f scpritfiles(1)'|' 只是用来说明性的分隔 adress 和 command,实际使用 ...

  2. CAF(C++ actor framework)(序列化之类,无需序列化,直接传)(二)

    昨天讲了Struct,还是不够满意,毕竟C++里面类用的比较多嘛,那就先上个类, 这段代码是我稍微改编了一下的结果.都是最基本的用法. #include <utility> #includ ...

  3. php parallel

    http://www.phpied.com/simultaneuos-http-requests-in-php-with-curl/ http://stackoverflow.com/question ...

  4. Ubuntu Android Studio/IntelliJ IDEA 支持文件中文命名

    Android Studio 默认字体无法使用中文命名文件,中文显示空心方块,使用思源字体,可解析 下载思源字体http://www.cnblogs.com/icgq/p/4195347.html 选 ...

  5. [Accessibility] Missing contentDescription attribute on image [可取行]失踪contentDescription属性图像

    问题描述: [Accessibility] Missing contentDescription attribute on image [可取行]失踪contentDescription属性图像 原因 ...

  6. C# CRC32

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  7. Centos7搭建集中式日志系统

    在CentOS7中,Rsyslong是一个集中式的日志收集系统,可以运行在TCP或者UDP的514端口上.   目录 开始之前 配置接收日志的主机 配置发送日志的主机 日志回滚 附件:创建日志接收模板 ...

  8. 【转】perl ping检测功能脚本代码

    我的第一个用于生产环境的perl脚本,虽然不是很优秀,但也迈出了扎实的一步 :)领导有任务,给一批IP列表,ping每一台机器,如果没有响应就发邮件通知,通知的邮件需要分开,不能通知一个列表,得一封一 ...

  9. Only the original thread that created a view hierarchy can touch its views

    在调试软件的时候出现如下的错误: 01-05 20:53:36.492: E/ZZShip(2043): android.view.ViewRootImpl$CalledFromWrongThread ...

  10. 拉链法解决Hash节点冲突问题

    <?php /* * hash::拉链法解决hash节点存储冲突问题 * ::2014-07-02 * ::Small_Kind */ class small_hash { private $s ...