Android: checkbox listener

Roman Rdgz picture Roman Rdgz · Dec 5, 2011 · Viewed 211.8k times · Source

I want to put a Listener over a CheckBox. I looked for info and it is like this:

satView = (CheckBox)findViewById(R.id.sateliteCheckBox);

satView.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        if (isChecked){
            // perform logic
        }
    }

});

The problem is that Eclipse thinks it's an OnCheckedChangeListener for a RadioGroup and it doesn't work. How can I fix this?

Answer

Chris picture Chris · Dec 5, 2011

You can do this:

satView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

       @Override
       public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {

       }
   }
);