ANDROID_MARS学习笔记_S01_005CheckBox
一、
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的更多相关文章
- ANDROID_MARS学习笔记_S01_012_RatingBar
1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ...
- ANDROID_MARS学习笔记_S01_012_SeekBar
1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ...
- ANDROID_MARS学习笔记_S01_011ProgressBar
文档是这样来设置样式 <ProgressBar android:layout_width="wrap_content" android:layout_height=" ...
- ANDROID_MARS学习笔记_S01_010日期时间控件
1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ...
- ANDROID_MARS学习笔记_S01_009Relative_LAYOUT例子
1. <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android ...
- ANDROID_MARS学习笔记_S01_008Linear_layout例子
1.netstone_layout.xml <?xml version="1.0" encoding="utf-8"?> <LinearLay ...
- ANDROID_MARS学习笔记_S01_007Linear_layout嵌套与layout_weight的设置
一.介绍 二.1.linear_layout.xml <?xml version="1.0" encoding="utf-8"?> <Line ...
- ANDROID_MARS学习笔记_S01_006ImageView
一.ImageView介绍 设置scalType Must be one of the following constant values. Constant Value Description ma ...
- ANDROID_MARS学习笔记_S01_004dpi、dp(dip)及计算
一.dpi.dp介绍 sp会随着用户在手机中设置字体大小而改变,而dp不会 二.1.dpsp_layout.xml <?xml version="1.0" encoding= ...
随机推荐
- NodeJS V8 GC概览
[A tour of V8: Garbage Collection] http://jayconrod.com/posts/55/a-tour-of-v8-garbage-collection 基本是 ...
- js 书写规范
1.字符串用单引号 2.运算符号和变量之间用空格建立间距 3.书写插件时使用 'use strict'; 开头 4.方法如果是获取或者设置数据集合则使用动词如 getData,setData,eac ...
- jqGrid API 相关
取消所有选中的行: $("jqgridtableid").trigger("reloadGrid"): 设定选中行,可设定多行选中: $("jqgri ...
- Js 对象三
一.screen对象 Width:屏幕的宽度 Height:屏幕的高度 availWidth:屏幕的有效宽度 availhHeight:屏幕的有效高度 (不包含任务栏) colorDepth:色深 二 ...
- 安装WP8 SDK出现“根据当前系统时钟或签名文件中的时间戳验证时要求的证书不在有效期内”的解决办法
今天重装系统了,在安装WP8 SDK时,安装了一小部分就提示“根据当前系统时钟或签名文件中的时间戳验证时要求的证书不在有效期内”的错误. 根据错误提示,貌似跟时间有关,百度了下.果真.把系统时间往前调 ...
- 基础学习总结(三)--文本、SD卡数据读写
简单的文本数据写入文件不需要权限,读写SD卡在4.0版本前需要写权限.在4.0后需要读写权限 布局: <LinearLayout xmlns:android="http://schem ...
- 用JS写的无缝滚动特效
代码如下 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta ...
- delphi 自带报告内存泄漏
//报告内存泄漏 ReportMemoryLeaksOnShutdown := true;
- Catalyst揭秘 Day7 SQL转为RDD的具体实现
Catalyst揭秘 Day7 SQL转为RDD的具体实现 从技术角度,越底层和硬件偶尔越高,可动弹的空间越小,而越高层,可动用的智慧是更多.Catalyst就是个高层的智慧. Catalyst已经逐 ...
- Arcgis投影变换后图像变深的问题
首先投影时,重采样方式选择nearest最邻近采样法,不改变投影后图像的DN值。 然后双击投影后图像,在符号系统中选择RGB——拉伸类型改为:无(默认是标准差拉伸)