title: Android java: button's color toggling 'line' @ bottom doesn't toggle properly
body: <p>I've researched this high &amp; low, both on here, and the intertubes in general.  Unfortunately, I've found nothing applicable, even on the 'droid java API for the <code>Button</code> class.</p>
  
  <p>In my application, I have a button that I'm using to toggle playback of an <code>AudioTrack</code>.  When this button is toggled manually, the horizontal bar at the bottom of (but still within the confines of) the button switches color correctly.  This being black when not playing, and red when playing, though I did not code anything regarding this feature.</p>
  
  <p>Unfortunately, when the button is toggled via code from within an <code>AudioTrack</code> listener's anonymous method/function, this color change does not occur.  As a result, the color changing of the button's bar alternates color changing behavior with every play allowed to complete.  Listener code follows:</p>
  
  <pre><code>public void onMarkerReached(AudioTrack track) {
    if (playing &amp;&amp; !continuous) {
      ouahful.stop();
      btnTogglePlayback.setText(
        getResources().getString(
          R.string.text_off));
      playing = !playing;
    }
  }
  </code></pre>
  
  <p>Toggling code follows:</p>
  
  <pre><code>public void onTogglePlay(View view) throws MyException {
      byte    sounds[] = initSound(freq);
      /* AudioTrack  ouahful = new AudioTrack(AudioManager.STREAM_MUSIC,
              sampleRate, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT,
              sounds.length, AudioTrack.MODE_STATIC); */
  
      if (!playing) {
          if (regen) {
              sounds = initSound(freq);
          }
          ouahful = buildTrack(sounds);
          ouahful.setNotificationMarkerPosition(numSamples);
  
          setATListeners();
          btnTogglePlayback.setText(getResources().getString(R.string.text_on));
          ouahful.play();
      } else {
          btnTogglePlayback.setText(getResources().getString(R.string.text_off));
          ouahful.stop(); //need to convert to save the track beyond this method
      }
  
      if ((freq != getResources().getInteger(R.integer.freq1)) &amp;&amp;
              (freq != getResources().getInteger(R.integer.freq2)) &amp;&amp;
              (freq != getResources().getInteger(R.integer.freq3))) {
          rgrp.clearCheck();
      }
  
      btnSetManually.setEnabled(false);
      playing = !playing;
  }
  </code></pre>
  
  <p>I don't <em>think</em> any other code snippets are applicable to this issue.  My apologies if I'm wrong on that, please feel free to let me know what other information would be helpful for this issue.</p>
  
  <p>Many thanks to any information and/or pointers thereto on solving this!</p>