- 浏览: 133486 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
devilyard:
msdghs 写道JS中没有continue,直接return ...
js for循环,符合某一条件则跳过并进行下次循环 -
msdghs:
JS中没有continue,直接return fasle就行
js for循环,符合某一条件则跳过并进行下次循环 -
LD_21:
js for循环,符合某一条件则跳过并进行下次循环 -
DanielHan:
在avd上测试,不会出现这种情况?
android EditText控件自动获取焦点弹出键盘解决方法 -
Mr.Joe:
logoyang88 写道问题解决了吗,字体颜色怎么修改呢,请 ...
浏览器input输入框修改黄色背景色
Android中CheckBox控件使用可以通过两种方法实现
1、OnClickListener
2、OnCheckedChangeListener
布局文件
控制文件
1、OnClickListener
2、OnCheckedChangeListener
布局文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <CheckBox android:id="@+id/all_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="全选" /> <CheckBox android:id="@+id/first_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="选项1" /> <CheckBox android:id="@+id/secend_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="选项2" /> <CheckBox android:id="@+id/third_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="选项3" /> <CheckBox android:id="@+id/fourth_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="选项4" /> </LinearLayout>
控制文件
package com.geoffrey.practice_checkbox; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; public class MainActivity extends Activity { private CheckBox allCheckBox; private CheckBox firstCheckBox; private CheckBox secendCheckBox; private CheckBox thirdCheckBox; private CheckBox fourthCheckBox; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_checkbox); allCheckBox = (CheckBox) findViewById(R.id.all_checkbox); firstCheckBox = (CheckBox) findViewById(R.id.first_checkbox); secendCheckBox = (CheckBox) findViewById(R.id.secend_checkbox); thirdCheckBox = (CheckBox) findViewById(R.id.third_checkbox); fourthCheckBox = (CheckBox) findViewById(R.id.fourth_checkbox); // 给第一个和第二个CheckBox控件绑定OnCheckBoxClickListener方法 OnCheckBoxClickListener listener = new OnCheckBoxClickListener(); firstCheckBox.setOnClickListener(listener); secendCheckBox.setOnClickListener(listener); // 给第三个和第四个CheckBox控件绑定CheckBoxListener方法 CheckBoxListener listener2 = new CheckBoxListener(); thirdCheckBox.setOnCheckedChangeListener(listener2); fourthCheckBox.setOnCheckedChangeListener(listener2); // 全选,全部取消 allCheckBox.setOnClickListener(listener); } // 内部类OnCheckBoxClickListener,使用OnClickListener方法监听 class OnCheckBoxClickListener implements OnClickListener { @Override public void onClick(View view) { CheckBox checkBox = (CheckBox) view; if (checkBox.getId() == R.id.first_checkbox) { System.out.println("点击第一个checkbox"); } else if (checkBox.getId() == R.id.secend_checkbox) { System.out.println("点击第二个checkbox"); } if (checkBox.isChecked()) { System.out.println("选中"); if (checkBox.getId() == R.id.all_checkbox) { firstCheckBox.setChecked(true); secendCheckBox.setChecked(true); thirdCheckBox.setChecked(true); fourthCheckBox.setChecked(true); } } else { System.out.println("取消选中"); allCheckBox.setChecked(false); if (checkBox.getId() == R.id.all_checkbox) { firstCheckBox.setChecked(false); secendCheckBox.setChecked(false); thirdCheckBox.setChecked(false); fourthCheckBox.setChecked(false); } } } } // 内部类CheckBoxListener,使用OnCheckedChangeListener方法监听 class CheckBoxListener implements OnCheckedChangeListener { @Override /** * @param buttonView 点击选中的控件 * @param isChecked 是否选中状态 */ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (buttonView.getId() == R.id.third_checkbox) { System.out.println("点击第三个checkbox"); } else if (buttonView.getId() == R.id.fourth_checkbox) { System.out.println("点击第四个checkbox"); } if (isChecked) { System.out.println("选中"); } else { System.out.println("取消选中"); allCheckBox.setChecked(false); } } } }
发表评论
-
Webview缓存处理
2017-07-11 09:01 1533之前做了一个功能,用WebView加载一个网页,网页里有登录等 ... -
Android 拨打电话功能
2016-04-06 17:27 427Android拨打电话有两种方式,一种直接拨打,一种跳到拨号页 ... -
WebView中无法下载问题解决方法
2015-11-09 11:43 5370在webview中有时会遇到需要下载文件,这个时候点击下载没有 ... -
Android intent.setFlags方法中的参数值含义
2015-08-20 10:21 712一. intent.setFlags()方法中的参数值含义: ... -
Android再按一次退出程序实现方法
2015-08-14 15:34 733private long exitTime = 0; ... -
Android计时器
2015-08-13 10:08 618private Handler handler = ne ... -
Android手机调试log不全
2015-07-29 12:32 1376今天弄了个新手机 华为mate7,调试时候log很少,明显不全 ... -
Android去除标题栏及自定义title栏
2015-06-12 18:13 3880一、Android去标题栏方法: 1、针对单个页面进入页面的 ... -
android使用keystore打包错误解决方法
2015-05-29 11:02 1778打包时报如下错误: Export aborted becau ... -
动态设置控件宽高
2015-05-26 15:38 754Android中有的控件可以直接使用setHeight或是se ... -
android 获取屏幕宽高、密度、dpi
2015-05-26 15:33 1200获取屏幕宽高、密度、dpi DisplayMetrics ... -
Android httpClient Get&Post方法
2015-02-09 10:54 585GET方法: //先将参数放入List,再对参数进行URL ... -
Android GestureDetector滑动监听事件
2015-01-29 17:10 3347项目中需要做滑动监听 ... -
Android 自定义dialog
2014-12-12 10:56 2309自定义dialog分别需要样式、自定义布局、控制显示3部分 ... -
Android 键盘弹出\收起及监听
2014-12-10 11:09 53281、键盘显示则隐藏,没有显示则弹出 InputMethod ... -
Android使用include后仍然报错java.lang.NullPointerException
2014-12-09 18:44 1306今天在使用include时控制引入的layout控件总是报空指 ... -
Android 延迟执行方法
2014-12-15 13:25 931方法一: Timer timer = new Timer( ... -
Android ImageView显示网络图片
2014-12-05 13:19 1938String url = "http://192 ... -
Android中visibility的3个属性说明
2014-12-01 17:12 1450关于Android中visibility的属性 VISIBLE ... -
Android TextView显示html图片
2014-11-17 14:21 2711html = "<h1>this i ...
相关推荐
拥有三种状态纯Material风格的Android Checkbox控件
checkBox控件常见使用checkBox控件常见使用checkBox控件常见使用checkBox控件常见使用
android CheckBox的使用简单实例。
Android CheckBox与监听Demo源码.rar
checkbox控件的一些简单使用,包括checkbox的选项的选择,和集合内项的增删等功能
简单实现自定义checkbox控件四种选择状态的图片样式
android 的listview 内部item的布局包含checkbox控件时,会遇到常见的问题:1.checkbox无法选择;2.选择的checkbox后滑动listview内容时会checkbox选择的值会刷新成原来状态值(即没选中);3.选择listview所有checkbox...
Android基本控件使用示例,包含以下控件实例: AutoCompleteTextView CheckBox TimePicker DatePicker EditText GridView ImageButton ImageShow ImageView ProgressBar RadioGroup RatingBar SeekBar Spinner Tab
MFC实现动态创建COMBOX控件以及CHECKBOX控件的例子,还有在类里头创建线程的应用
找了一些关于checkboxList控件的常用用法 添加项,选择项,删除项的等17种常用的方法。 希望对大家有用
android checkbox 的isChecked属性
c# checkbox控件的使用总结:1.根据ini文件的0,1二进制字符串,勾选checkbox控件 2.根据选中的checkbox控件,组成字符串
Android checkbox 实现单选,代码较少,布局简单
android listview和checkbox联合使用,选中和取消
android checkbox全选反选
<item name="android:button">@drawable/selector</item>//这个selector.xml中就是对应不同状态的CheckBox的背景图片 3:在selector.xml <selector xmlns:android=...
原始的Android CheckBox 控件难看,而且占据的位置较大,给开发者带来不便。
这是一个自己编写的CheckBox控件制作代码,对于初学者来说有很大的帮助,对于控件使用上也是一个很大的提高。
Android 带有切换动画的CheckBox