Android基本组件04(CheckBox)
来源:互联网 发布:户外刀具淘宝网 编辑:程序博客网 时间:2024/05/23 02:06
//ActivityCheckBox.javapackage android.ActivityUI;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.CheckBox;public class ActivityCheckBox extends Activity{CheckBox Monday_id;CheckBox Tuesday_id;CheckBox Wednesday_id;CheckBox Thursday_id;CheckBox Friday_id;CheckBox Saturday_id;CheckBox Sunday_id;public void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.check_box);setTitle("CheckBox");getChecked();}private void getChecked(){Monday_id = (CheckBox)findViewById(R.id.id0);Tuesday_id = (CheckBox)findViewById(R.id.id1);Wednesday_id = (CheckBox)findViewById(R.id.id2);Thursday_id = (CheckBox)findViewById(R.id.id3);Friday_id = (CheckBox)findViewById(R.id.id4);Saturday_id = (CheckBox)findViewById(R.id.id5);Sunday_id = (CheckBox)findViewById(R.id.id6);Button button_get_check = (Button)findViewById(R.id.button_get_check);button_get_check.setOnClickListener(get_check_listener);}private Button.OnClickListener get_check_listener = new Button.OnClickListener(){public void onClick(View v){String checked = "";if(Monday_id.isChecked()){checked = checked + Monday_id.getText() + ";";}if(Tuesday_id.isChecked()){checked = checked + Tuesday_id.getText() + ";";}if(Wednesday_id.isChecked()){checked = checked + Wednesday_id.getText() + ";";}if(Thursday_id.isChecked()){checked = checked + Thursday_id.getText() + ";";}if(Friday_id.isChecked()){checked = checked + Friday_id.getText() + ";";}if(Saturday_id.isChecked()){checked = checked + Saturday_id.getText() + ";";}if(Sunday_id.isChecked()){checked = checked + Sunday_id.getText() + ";";}setTitle("checked:"+checked);}};}//check_box.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"> <CheckBoxandroid:id="@+id/id0"android:text="Monday"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textStyle="normal"/><CheckBoxandroid:id="@+id/id1"android:text="Tuesday"android:layout_width="wrap_content"android:layout_height="wrap_content"/><CheckBox android:text="Wednesday" android:id="@+id/id2" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox><CheckBox android:text="Thursday" android:id="@+id/id3" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox><CheckBox android:text="Friday" android:id="@+id/id4" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox><CheckBox android:text="Saturday" android:id="@+id/id5" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox><CheckBox android:text="Sunday" android:id="@+id/id6" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox><Button android:text="get checked" android:id="@+id/button_get_check" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button></LinearLayout>
举个例子,如选择Saturday、Sunday, 然后点击get checked 按钮:
- Android基本组件04(CheckBox)
- 一步一步学android之基本控件——CheckBox组件
- Android学习笔记八:基本视图组件:CheckBox
- Android组件复习之基本组件02—单选按钮(RadioButton)和复选框(CheckBox)
- Android组件复习之基本组件02—单选按钮(RadioButton)和复选框(CheckBox)
- Android组件 多项选择(CheckBox)
- android组件之checkbox
- Android组件之CheckBox
- Android视图组件: CheckBox
- Android 组件学习--CheckBox
- android 组件CheckBox实例
- Android-基本控件(CheckBox,RadioGroup,RadioButton)
- Android 基本组件(一)
- Android UI之CheckBox组件
- android基本控件RadioButton/CheckBox
- 在内部存储中写文件详解(组件CheckBox的基本用法)
- Android基本组件02(TextView)
- Android基本组件03(EditText)
- 长篇文章分页
- 建立时间与保持时间
- 微软架构师谈编程语言发展
- 教师节写给我自己:一个没有教师资格证,却被称为老师的人
- JAVA面试题大全
- Android基本组件04(CheckBox)
- hdu 1536
- Python3写的小工具,windows下杀死进程
- Java面试题
- SQLServer 批量备份与还原
- 提问的智慧-从看雪学院转来的
- NOR Flash
- IE中使用FireBug,此法极度实用啊。。
- strlen(str)和sizeof(str)