Checkbox和RadioRadioButton及其实例
来源:互联网 发布:earpods 知乎 编辑:程序博客网 时间:2024/05/18 23:25
学习目标:掌握Checkbox和RadioRadioButton;掌握OnCheckedChangeListener的使用。
一:CheckBox的使用
一:定义及特性
1:CheckBox是选择框,只有选中和未选中两种状态。
2:一半使用在多个选项都可以选择的情况下,例如:选择你感兴趣的话题。
3:OnCheckedChangeListener是CompoundButton下的监听对象,因为CheckBox是CompoundButton的子类,所以OnCheckedChangeListener可以直接使用。
二:例子
<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:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp" android:text="请选择你的爱好" /> <CheckBox android:id="@+id/playball" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="玩球" /> <CheckBox android:id="@+id/readnovel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="读小说" /> <CheckBox android:id="@+id/playgame" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="打游戏" /> <CheckBox android:id="@+id/readbooks" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="读书" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="查看选中" /></LinearLayout>
private Button check; private CheckBox playball,readnovel,readbooks,playgame;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main); check=(Button)findViewById(R.id.button1); playball=(CheckBox)findViewById(R.id.playball); readnovel=(CheckBox)findViewById(R.id.readnovel); readbooks=(CheckBox)findViewById(R.id.readbooks); playgame=(CheckBox)findViewById(R.id.playgame); //使用匿名内部类进行监听 check.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {// TODO 自动生成的方法存根shoecheck();}private void shoecheck() {// TODO 自动生成的方法存根String str = "";if(playball.isChecked()){str+=playball.getText().toString();}if(readnovel.isChecked()){str+=readnovel.getText().toString();}if(readbooks.isChecked()){str+=readbooks.getText().toString();}if(playgame.isChecked()){str+=playgame.getText().toString();}}});}结果
阅读全文
1 0
- Checkbox和RadioRadioButton及其实例
- radio控件和checkbox实例
- ExtJs之Radio和CheckBox实例
- CheckBox实例
- checkbox 实例
- Android--CheckBox复选框、RadioGroup和RadioButton及其使用
- TextInput、RadioButton、CheckBox、Combobox组件的使用和实例
- 关于checkbox的全选和反选实例
- checkbox的extjs实例
- ALV checkbox实例
- Android CheckBox应用实例
- 全选checkbox实例
- android 组件CheckBox实例
- checkbox全选实例
- UI组件之TextView及其子类(二)RadioButton和CheckBox
- SpringMVC入门教程及其原理讲解和实例代码下载
- MKNetworkKit入门和简单使用及其源码实例分析
- SpringMVC入门教程及其原理讲解和实例代码下载
- javascript里面的数据类型有哪些
- 基于jquery的树形列表TreeGrid
- PyQt初级教程
- 约瑟夫环的java实现
- 从veth看虚拟网络设备的qdisc
- Checkbox和RadioRadioButton及其实例
- 纯手工打造mini linux实例
- LINUX常用命令详解
- 看懂FTP的主动和被动模式
- hdu 1530最大团模板
- LibreOJ Round #4 A.游戏
- level set 模型介绍
- python提取GIST特征,安装pyleargist包
- R语言在直方图上添加正太曲线与核密度曲线