title: Android: ToggleButton Listener
body: <p>I have this code here</p>
  <pre><code>ToggleButton toggleAlarm = (ToggleButton) d.findViewById(R.id.toggle_alarm);
  toggleAlarm.setOnCheckedChangeListener(new OnCheckedChangeListener() {
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
          if(isChecked)
          {
              Log.d(&quot;alarmCheck&quot;,&quot;ALARM SET TO TRUE&quot;);
              sched.setAlarm(true);
          }
          else
          {
              Log.d(&quot;alarmCheck&quot;,&quot;ALARM SET TO FALSE&quot;);
              sched.setAlarm(false);
          }
      }
  });
  </code></pre>
  <p>I have to keep track if its ON or OFF. But when I logged something to logcat where it is on or off, it won't do a thing. I don't know, what is wrong, because on my other code same, syntax but it works I just copy paste it and change only the ToggleButton variable.</p>
  <h2><strong>EDIT</strong></h2>
  <p>I have observed, with the help of cdr. Powell of course, that when you put this code block, the one that I have posted, inside another anonymous listener, say listener for a save button, the checkOnChangedListener is broken, it doesn't function well inside another anonymous listener, but the one thing that I don't understand is that, there is also a outer listener in my code, it is like a button to display a dialog box and inside that dialog box, there is an add button that opens another dialog box which has that toggle button and another button for save or add which closes that dialog and returns to the previous dialog which will then display the newly added record, so anyone of you have an idea why is it broken when i put it inside a listener for a save button but works fine in a outer listener.</p>