android-checkbox监听器的问题

问题描述

checkbox监听器的问题
我想在 checkBox上设置一个监听器。查找过资料后,我写了如下的代码:

 satView = (CheckBox)findViewById(R.id.sateliteCheckBox);    satView.setOnCheckedChangeListener(new OnCheckedChangeListener() {        @Override        public void onCheckedChanged(RadioGroup group int checkedId) {            if (isChecked){                // perform logic            }        }    });

但是在Eclipse认为它是RadioGroup的OnCheckedChangeListener监听器,不是我想实现的效果。大家知道如何给checkbox设置监听器吗?

解决方案

你可以使用以下方法:

satView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {   @Override   public void onCheckedChanged(CompoundButton buttonViewboolean isChecked) {   }}

解决方案二:

satView = (CheckBox)findViewById(R.id.sateliteCheckBox);satView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {    @Override    public void onCheckedChanged(CompoundButton buttonView boolean isChecked) {        if (isChecked){            // perform logic        }    }});

解决方案三:

satView = (CheckBox)findViewById(R.id.sateliteCheckBox);    satView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {        @Override        public void onCheckedChanged(RadioGroup group int checkedId) {            if (isChecked){                // perform logic            }        }    });
时间: 2024-07-28 16:55:22

android-checkbox监听器的问题的相关文章

详解Android Checkbox的使用方法_Android

0和1是计算机的基础,数理逻辑中0和1代表两种状态,真与假.0和1看似简单,其实变化无穷. 今天我就来聊聊android控件中拥有着0和1这种特性的魔力控件checkbox. 先来讲讲Checkbox的基本使用.在XML中定义. <?xml version="1.0" encoding="utf-8"?> <CheckBox xmlns:android="http://schemas.android.com/apk/res/android

android checkbox复选框不显示

问题描述 android checkbox复选框不显示 做了一个显示文件列表的app 列表每一项右边的checkbox复选框在安卓5.0系统中显示出来了 把app装到4.0+的系统中就不显示了 一直都找不到原因 麻烦各位大神解救 在4.0+的系统中右边的复选框不显示 但点击了代码提示还是又选中了 它还是在那个位置 但就是显示不出来 解决方案 Android中CheckBox复选框操作android 中 CheckBox 复选框操作Android复选框(CheckBox)的现实

android textchange监听器

问题描述 android textchange监听器 功能需求:如果text是空的,就不调用textchange监听器. public void afterTextChanged(Editable s) { if(et1.getText().toString().length() == 0){ et1.removeTextChangedListener(watcher); et1.setText(""); } } 为什么不实现? 解决方案 你何不试试其他两个方法呢,点到为止,看自己悟性

android程序监听器的地方有错出错

问题描述 android程序监听器的地方有错出错 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); P1=(ProgressBar)findViewById(R.id.P1); P2=(ProgressBar)findViewById(R.id.P2); button=(Button)fin

Android checkbox的listView(多选,全选,反选)具体实现方法_Android

布局文件:[html]  复制代码 代码如下: <?xml version="1.0" encoding="utf-8"?>  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="fill_parent"      android:layout_height=

Android Checkbox详解

原文出处:Ocean-藏心  0和1是计算机的基础,数理逻辑中0和1代表两种状态,真与假.0和1看似简单,其实变化无穷. 今天我就来聊聊android控件中拥有着0和1这种特性的魔力控件checkbox. 先来讲讲Checkbox的基本使用.在XML中定义. <?xml version="1.0" encoding="utf-8"?> <CheckBox xmlns:android="http://schemas.android.com/

详解Android Checkbox的使用方法

0和1是计算机的基础,数理逻辑中0和1代表两种状态,真与假.0和1看似简单,其实变化无穷. 今天我就来聊聊android控件中拥有着0和1这种特性的魔力控件checkbox. 先来讲讲Checkbox的基本使用.在XML中定义. <?xml version="1.0" encoding="utf-8"?> <CheckBox xmlns:android="http://schemas.android.com/apk/res/android

Android checkbox的listView(多选,全选,反选)具体实现方法

布局文件: [html]  复制代码 代码如下: <?xml version="1.0" encoding="utf-8"?>  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="fill_parent"      android:layout_height

Android CheckBox设置背景selector和文本text 设置selectColor

1. android:button="@null" 可以屏蔽CheckBox的选择框 2.android:textColor="@drawable/selector_text_color"  文本text 设置selectColor 效果图: <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" and

android Animation监听器AnimationListener的使用方法)_Android

AnimationListener听名字就知道是对Animation设置监听器,说简单点就是在Animation动画效果开始执行前,执行完毕和重复执行时可以触发监听器,从而执行对应的函数. 开发环境为android4.1.AnimaitonListener的使用方法主要是在Animation上设置一个监听器,即采用Animation的方法成员setAnimationListener().其参数就是监听器的函数.现在来说说本次实验的功能,主要有2个按钮,一个是增加图片的按钮,一个是删除图片的按钮,