Android控件开发之CheckBox
来源:互联网 发布:如何复制淘宝上的图片 编辑:程序博客网 时间:2024/06/05 07:47
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()
- {
- @Override
- public 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;
- }
- }
- };
0 0
- 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
- Android控件开发之EditView
- Windows下Python包和模块的安装方法
- 2.16-switch
- Unity 之 C# 利用回调函数实现C++匿名函数
- 课堂笔记03
- Android控件开发之CheckBox
- linux input子系统(一)
- hdu 4251 划分树入门题
- Android唤醒锁问题
- Maven Unable to locate the Javac Compiler
- 2.17-switch练习
- contentType,charset和pageEncoding的区别
- 关于java项目路径问题
- mysql的InnoDB参数详解