如何接收Android上的事件复选框检查更改? [英] How to receive a event on android checkbox check change?

查看:102
本文介绍了如何接收Android上的事件复选框检查更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当复选框启用或禁用时,接收和发送事件的正确方法是什么。在c#我可以只是轻松双击,所有的代码将为我完成。但在Android中它似乎有点更加模糊。我想到使用触摸事件处理程序,但然后如果用户有一个键盘,它不会检测到更改,因为它没有触摸。我想图android应该有一个原生事件为复选框状态更改。

what would be the correct way of receiving and sending a event when a check box get's enable or disable. In c# i could just easily double click and all the code would be done for me. but in android it appears to be a bit more obscure. i thought of using the touch event handlers but then if the user has a keyboard it wont detect the change since it's not touch. I figure android should have a native event for check box state change.

推荐答案

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

    }
});

这篇关于如何接收Android上的事件复选框检查更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆