麦子学院Android开发教程复选框源码解析

麦子学院Android开发教程复选框源码解析

IT在线教育平台———麦子学院:https://www.360docs.net/doc/1e7225022.html,

学习android从一些基本的框架结构了解起,,今天就为大家讲解Android复选框的基

本概念。

●设置复选框的Check状态的时候,调用setChecked()方法

●追加Android复选框被选择时处理的时候,

1.调用setOnCheckedChangeListener()方法,并把

CompoundButton.OnCheckedChangeListener实例作为参数传入

2.在CompoundButton.OnCheckedChangeListener的onCheckedChanged()方法里,取得被选中Android复选框的实例

例程源码(Java)

1.CheckBox checkBox = (CheckBox) findViewById(id.checkBox);

2.checkBox.setChecked(true);

3.checkBox.setOnCheckedChangeListener(

4.new CompoundButton.OnCheckedChangeListener() {

5.@Override

6.public void onCheckedChanged(

https://www.360docs.net/doc/1e7225022.html,poundButton buttonView,

8.boolean isChecked) {

9.CheckBox checkBox = (CheckBox) buttonView;

10.Log.v("Test", String.valueOf(checkBox.getText()) +

11." is " + String.valueOf(isChecked));

12.}

13.});

复制代码

例程源码(Resource)

1.< CheckBox android:id="@+id/checkBox"

2.android:layout_width="wrap_content"

3.android:layout_height="wrap_content"

4.android:text="@string/test" />

复制代码

如需了解更多相关知识,请至麦子学院官网查询(https://www.360docs.net/doc/1e7225022.html,/)。

相关主题
相关文档
最新文档