Android学习笔记之CheckBox
来源:互联网 发布:西方主要哲学流派 知乎 编辑:程序博客网 时间:2024/05/16 12:59
CheckBox复选按钮是一种有双状态按钮的特殊类型,可以选中或者不选中。可以现在布局文件中定义多选按钮,然后对每一个多选按钮进行事件监setOnCheckedChangeListener,通过isChecked来判断选项是否被选中
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="wrap_content" android:layout_height="wrap_content" android:text="@string/theme" /> <CheckBox android:id="@+id/apple" android:text="@string/apple" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <CheckBox android:id="@+id/banana" android:text="@string/banana" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout>
RadioGroupActivity.java
package Android.Activity;import android.app.Activity;import android.os.Bundle;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.Toast;public class RadioGroupActivity extends Activity { /** Called when the activity is first created. */private CheckBox appleCheck = null;private CheckBox bananaCheck = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //通过控件的ID来得到代表控件的对象 appleCheck = (CheckBox)findViewById(R.id.apple); bananaCheck = (CheckBox)findViewById(R.id.banana); //为RadioGroup设置监听器,需要注意的是,这里的监听器和Button控件的监听器有所不同 appleCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {// TODO Auto-generated method stubif(isChecked){Toast.makeText(RadioGroupActivity.this,"恭喜你,还剩很多苹果", Toast.LENGTH_LONG).show();}}}); bananaCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {// TODO Auto-generated method stubif(isChecked){Toast.makeText(RadioGroupActivity.this,"恭喜你,还剩很多香蕉", Toast.LENGTH_LONG).show();}}}); }}
- Android学习笔记之CheckBox
- android学习之CheckBox
- android学习之CheckBox
- Android学习笔记之判断checkbox是否选中
- Android UI学习笔记 之RadioButton和CheckBox的使用
- Android UI学习之CheckBox
- android学习笔记12:RadioButton和checkbox
- Android之CheckBox,RadioGroup(笔记)
- Android之CheckBox,RadioGroup(笔记)
- Android学习路之RadioButton&Checkbox
- 【学习笔记】imageview,checkbox
- Android开发学习笔记:RadioButton和CheckBox浅析
- Android学习笔记(三)checkbox和radiobutton
- android学习笔记05(RadioGroup,CheckBox,Toast)
- Android开发学习笔记:RadioButton和CheckBox浅析
- 【Android学习笔记】RadioGroup,RadioButton的使用&CheckBox的使用
- Android开发————CheckBox学习笔记
- Android学习笔记八:基本视图组件:CheckBox
- Android学习笔记之RadioButton(RadioGroup)
- Windows程序设计__孙鑫C++Lesson3《MFC 程序框架的剖析》
- IT人员迅速提升自我效率的十大方法
- Git简介
- 浮点数的反汇编
- Android学习笔记之CheckBox
- Android UI 之TextView控件中可选择的属性列表,开发中经常用到的
- .NET三层架构解析
- install apache mason
- 2011年软件研发十大关键词盘点
- linux initrd
- Android 开发人员必须掌握的 10 个开发工具
- WindowsXP下搭建GIT服务器
- GIT服务器使用基础