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() {@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {if(isChecked) {Toast.makeText(CheckBoxActivity.this, "您选择了体育!", Toast.LENGTH_SHORT).show();}}});                this.movieCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {if(isChecked) {Toast.makeText(CheckBoxActivity.this, "您选择了电影!", Toast.LENGTH_SHORT).show();}}});    }}

更多相关文章

  1. 【AS基础篇二:线性布局和相对布局的使用】:设计一个简单的电影界
  2. 体育迷的工作:安卓开发,上海,国内排名第一体育平台
  3. Android 仿3g体育门户客户端赛事图标浮出效果
  4. android弹力效果菜单、组件化项目、电影选座控件的源码
  5. 使用requests+正则表达式爬取猫眼电影排行
  6. Python数据可视化:豆瓣电影TOP250
  7. Python数据可视化:2018年电影分析
  8. 破解X眼电影字体动态加密|凹凸玩数据
  9. 用python爬取3万多条评论,看韩国人如何评价韩国电影《寄生虫》?

随机推荐

  1. 微信支付接口 For Android(安卓)上手指南
  2. android 注解简介三: 自定义注解实现视图
  3. Android ProgressDialog 最佳处理方式
  4. Android(安卓)dumpsys命令的使用
  5. Android App 开发经验总结
  6. Android 中Service生命周期
  7. android 学习 之 布局(下)LinearLayout,Rela
  8. 新安装Android(安卓)Studio遇到问题集合+
  9. android studio2.0解决办法 Plugin is to
  10. android 之JSON