Archiv for February, 2008


published: February 18th, 2008

Android CheckBox OnCheckedChangeListener

For whatever reason I was having problems getting this code to work, but finally played with it enough and thought I’d write a quick post so I had a reference for later. I was looking for code which demonstrated a listener for the Android CheckBox view widget. I saw some examples of the OnClickListener but was trying to implement the OnCheckedChangeListener. Here is the code I used

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

    }
});

Part of the problem I was having was that the Android Eclipse plugin wasn’t recognizing the onCheckChanged method so the auto implementation wasn’t working, but when I pasted it in it worked fine.