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= ...
随机推荐
- C 再识数组指针 指针数组的概念
参考出处: http://www.cnblogs.com/mq0036/p/3382732.html http://www.cnblogs.com/hongcha717/archive/2010/10 ...
- python练习 根据日志中的ip和url排序
#!/usr/bin/env python #coding:utf-8 def open_file(file_name): res={} with open(file_name) as f: for ...
- 3.IP转发
1. "vim /usr/lib/sysctl.d/00-system.conf"在#Disable netfilter on bridges.栏下面添加行:"net. ...
- 从一个乘法来分析C语言
昨天碰到一个很奇怪的问题,首先来看这段代码: #include<stdio.h> int main(int argc,char *argv[]) { ; ; long long res1 ...
- linux ubuntu 思源黑体安装
下载地址: 全部:700多M https://github.com/adobe-fonts/source-han-sans/releases/tag/1.001R 可选部分Github : http ...
- ASP.NET的WebFrom组件LinkButton使用
在ASP.NET的WebForm组件中的LinkButton组件也是一个服务器端的组件,这个组件有点类似于HTML中的<A>标识符.它的主要作用是就是在ASP.NET页面中显示一个超链接. ...
- 玄机网C#论坛测试小游戏
http://files.cnblogs.com/ro4ters/EasyGame.zip http://www.xuanjics.com/thread-39-1-1.html 具体活动地址
- 如何保证写出来的程序没BUG
- JavaScript笔记(一)
JavaScript组成 EcmaScript:核心部分 作为解释器.几乎没有兼容性问题 DOM:Document Object Model,操作HTML页面的入口.有些操作不兼容. BOM:Brow ...
- splObjectStroge的作用,实例化一个数组
PHP SPL SplObjectStorage是用来存储一组对象的,特别是当你需要唯一标识对象的时候. PHP SPL SplObjectStorage类实现了Countable,Iterator, ...