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= ...
随机推荐
- SQL server 常见用法记录
-- ============================================= -- Author: tanghong -- Create da ...
- Source Insight 技巧总结
以下文章转载自网络:http://blog.csdn.net/junjie319/article/details/6910992 http://www.cnblogs.com/bluestorm/ar ...
- 小黑的镇魂曲(HDU2155:贪心+dfs+奇葩解法)
题目:点这里 题目的意思跟所谓的是英雄就下100层一个意思……在T秒内能够下到地面,就可以了(还有一个板与板之间不能超过H高). 接触这题目是在昨晚的训练赛,当时拍拍地打了个贪心+dfs,果断跟我想的 ...
- [设计模式]NetworkManagementService中的观察者模式
观察者模式 观察者模式有如下角色 (1)被观察者(Subject) (2)观察者(Observer) public class Subject{ private: list<Observer&g ...
- oracle 之路目录
oracle linux单机安装 oracle windows单机安装创建实例卡死解决办法 oracle rac安装 HPDL380G8平台11.2.0.3 RAC实施手册 pl-sql develo ...
- 在Mac OS X中使用VIM开发STM32(4)
本文原创于http://www.cnblogs.com/humaoxiao,非法转载者请自重! 在上三篇文章中,我们基本搭建好了开发STM32的IDE环境,当然vim.ctags.tagl ...
- php学习问题记录
1.微信应用开发,Token认证失败,解决方法php页面加上一句代码: header('content-type:text');
- Json对象序列化与反序列化
如果后台的参数数对象,需要在前台传入: JS代码: //创建JS对象 var CUTTING_TABLET_MO = new Object(); CUTTING_TABLET_MO.CUTTING_T ...
- WeX5与阿里内测的Weex与有何纠葛?快来看HTML5开发圈那些逗逼事儿!
4月21日~23日,由infoQ主办的2016 Qcon大会北京站如期举行. HTML5开发已经成为移动开发/前端专题中无可争议的焦点,核心议题已经由前几年的是否该用HTML5转向了如何高性能.高效率 ...
- HTML5会砸掉iOS和Android开发者的饭碗么?
原生App的颠覆 HTML5的“性工能”障碍得到解决,可以接近原生App的效果,所以它就可以替代原生App吗?很多人认为,即使HTML5会发展的比现在好,也将是与原生App各占一部分市场的格局,要求不 ...