title: how to restart a handler postdelay process if interupted during delay countdown
body: <p>I have a problem that i can't work out. I have a button that when clicked changes the text view. It then activates a <code>postdelayed</code> process that returns the <code>textview</code> to its original text after 2 seconds. </p>
  
  <p>If i press the button once, and then again within this 2 second interval the <code>postdelay</code> will continue to count down from the first press and not restart itself from the second press. This results in the original text being shown when i want the changed text to be. </p>
  
  <p>Each time the button is pressed it creates a delay from that instance. I want it to cancel the previous <code>postdelay</code> and start a new one. This is my code so far but its not finished because i can't work out how to finish it (so it does not work).</p>
  
  <pre><code>p1AddL.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              counter1 ++;
              count1 ++;
              Handler h = new Handler();
              if ('PREVIOUS_DELAY_HAS_STARTED') {
                  h.removeCallbacks(clickButton);
                  h.postDelayed(clickButton, 2000);
              } else {
                  h.postDelayed(clickButton, 2000);
              }
              if (count1 &gt; 0) {
                  lifepointsP1.setText("+" + count1);
                  lifepointsP1.setTextColor(Color.argb(220, 0, 188, 0));
              }
          }
      });
  
  Runnable clickButton = new Runnable() {
      @Override
      public void run() {
          count1 = 0;
          lifepointsP1.setTextColor(Color.WHITE);
          lifepointsP1.setText(counter1);
      }
  };
  </code></pre>
  
  <p>the <code>PREVIOUS_DELAY_HAS_STARTED</code> text needs to be some sort of checking method and i'm pretty sure i need something between the <code>h.removeCallbacks</code> and <code>h.postDelayed</code> commands under that text.</p>
  
  <p>If their is a simpler way/better way to write this method to make it work please let me know. I have tried so many ways and i feel i am very close here.</p>