attach onClickListener to ToggleButton

nkcmr picture nkcmr · Aug 22, 2011 · Viewed 59k times · Source

I have a ToggleButton and I need to set up simple click actions. How do I implement a simple click listener for a ToggleButton?

If you need details please ask.

Answer

Keith John Hutchison picture Keith John Hutchison · Sep 28, 2012
    this.someToggleButton = (ToggleButton)findViewById(R.id.someToggleButton) ;
    this.someToggleButton.setOnCheckedChangeListener( new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton toggleButton, boolean isChecked) {
            doSomethingWith(toggleButton, isChecked) ;
        }
    }) ;