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