Android控件开发之CheckBox
来源:互联网 发布:梁平知德小学怎么样 编辑:程序博客网 时间:2024/05/16 19:37
CheckBox,也就是多项选择。Android中提供了ChechBox控件,使用起来非常方便。
CheckBox效果
main.xml源码
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" ><TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/text"/> <CheckBox android:id="@+id/check1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="苹果 ios" /> <CheckBox android:id="@+id/check2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="谷歌 Android" /> <CheckBox android:id="@+id/check3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="RIM BlackBerry" /> <CheckBox android:id="@+id/check4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="微软 Windows phone 7" /> <CheckBox android:id="@+id/check5" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="诺基亚 symbian" /> <Button android:id="@+id/mybutton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="确定" /> </LinearLayout>CheckBox 事件响应setOnCheckedChangeListener
本程序java源码
import android.app.Activity;import android.os.Bundle;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.CompoundButton.OnCheckedChangeListener;import android.widget.Toast;public class CheckBoxActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main); final CheckBox check1 = (CheckBox)findViewById(R.id.check1);final CheckBox check2 = (CheckBox)findViewById(R.id.check2);final CheckBox check3 = (CheckBox)findViewById(R.id.check3);final CheckBox check4 = (CheckBox)findViewById(R.id.check4);final CheckBox check5 = (CheckBox)findViewById(R.id.check5); //创建CheckBox事件监听器 check1.setOnCheckedChangeListener(listener); check2.setOnCheckedChangeListener(listener); check3.setOnCheckedChangeListener(listener); check4.setOnCheckedChangeListener(listener); check5.setOnCheckedChangeListener(listener); } private OnCheckedChangeListener listener = new OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView,boolean isChecked){switch(buttonView.getId()){case R.id.check1:if(isChecked)Toast.makeText(getApplicationContext(), "你喜欢苹果 ios智能手机系统", Toast.LENGTH_LONG).show();break;case R.id.check2:if(isChecked)Toast.makeText(getApplicationContext(), "你喜欢谷歌 Android智能手机系统", Toast.LENGTH_LONG).show();break;case R.id.check3:if(isChecked)Toast.makeText(getApplicationContext(), "你喜欢RIM BlackBerry智能手机系统",Toast.LENGTH_LONG).show();break;case R.id.check4:if(isChecked)Toast.makeText(getApplicationContext(), "你喜欢微软 Windows phone 7智能手机系统", Toast.LENGTH_LONG).show();break;case R.id.check5:if(isChecked)Toast.makeText(getApplicationContext(), "你喜欢诺基亚 symbian智能手机系统", Toast.LENGTH_LONG).show();break;}} };
- Android控件开发之CheckBox
- Android控件开发之CheckBox
- Android控件之checkbox
- Android控件之CheckBox
- Android 控件之checkBox
- Android控件之CheckBox
- android控件之CheckBox
- Android控件之CheckBox
- Android开发--控件之RadioGroup、RadioButton、CheckBox、Toast
- CheckBox---Android控件系列之CheckBox
- android控件之radiobutton checkbox
- Android控件之CheckBox多选框
- Android控件之CheckBox、RadioButton
- Android控件系列之CheckBox
- Android自定义控件之CheckBox
- 【Android 开发】:UI控件之复选框控件 CheckBox 的使用方法
- Android游戏开发系统控件-CheckBox
- Android游戏开发系统控件-CheckBox
- 测试质量分析
- WinDBG 技巧:设断点命令详解(bp, bu, bm, ba 以及bl, bc, bd, be)
- 数组使用个人总结
- 一百年后,人类怎样编程?
- 让框架Frameset居中,并且固定宽度的巧妙办法
- Android控件开发之CheckBox
- poj 3709
- vi超强编辑器命令大全
- 会计手工记账流程
- Mysql 查看存储引擎
- 2.1变量名及2.2数据类型及长度
- 我的面试路
- 学计算机的,为什么要用linux?
- Android 开发之使用Eclipse Debug调试详解