main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<CheckBox
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/sportsCheckBox"
android:text="@string/sportsTxt"
/>
<CheckBox
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/movieCheckBox"
android:text="@string/movieTxt"
/>
</LinearLayout>
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">爱好选择</string>
<string name="app_name">CheckBox</string>
<string name="sportsTxt">体育</string>
<string name="movieTxt">电影</string>
</resources>
CheckBoxActivity.java
package com.qianlong.activity;
import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class CheckBoxActivity extends Activity {
private CheckBox sportsCheckBox;
private CheckBox movieCheckBox;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.sportsCheckBox = (CheckBox) this.findViewById(R.id.sportsCheckBox);
this.movieCheckBox = (CheckBox) this.findViewById(R.id.movieCheckBox);
this.sportsCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
Toast.makeText(CheckBoxActivity.this, "您选择了体育!", Toast.LENGTH_SHORT).show();
}
}
});
this.movieCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
Toast.makeText(CheckBoxActivity.this, "您选择了电影!", Toast.LENGTH_SHORT).show();
}
}
});
}
}
分享到:
相关推荐
* 具备良好的阅读文档和自学能力,能够与他人合作完成商用系统的需求分析、架构设计、软件编码与测试等工作 其他 * 熟悉面向对象思想、异常、数据结构、I/O、多线程和网络编程 * 熟练应用 Oracle、MySql、SQL...
"android开发练习demo"是一个典型的学习资源,它由一位自学Android应用开发的爱好者创建,旨在帮助初学者掌握基础控件的使用和调试技巧。这个压缩包包含了作者在学习过程中编写的几个小型应用程序示例,这些示例可以...
### Android程序员入门(中文版)知识点汇总 #### 一、Android概述 - **定义与历史**:Android是一种基于...无论是希望通过自学成为Android开发者的人群,还是希望扩展自己技能树的专业人士,都可以从本书中受益匪浅。
培训经历则进一步证明了开发者对软件工程理论、Android开发实践和团队合作的掌握,具备良好的文档阅读和自学能力。 总之,一个合格的Android程序员应该熟练掌握上述技能,并能在实际项目中灵活运用,解决复杂的技术...
4. **界面组件**:他熟练使用TextView、EditText、Button、Menu、Checkbox、ListView等Android界面组件,这表明他在构建用户界面方面有丰富的经验。 5. **数据存储**:对SQLite、File、SharedPreferences和网络存储...
这个资源包"实现列表多选的DEMO.zip"是一个针对Android平台的编程示例,主要展示了如何在...对于自学Android开发的人来说,这是一个很好的实践案例,可以深入理解Android的ListView、事件处理以及数据管理等核心概念。
这个“flex电子教案ppt”是一个专门为《flex完全自学手册》设计的教学资源,旨在帮助教师和学生深入理解Flex技术。 在Flex中,主要知识点包括: 1. **Flex架构**:Flex应用的基础是MXML和ActionScript 3.0,两者...