title: Simulate Android button click programmatically
body: <p>I've seen <a href="https://stackoverflow.com/questions/4553374/how-to-simulate-a-button-click-through-code-in-android">this</a> route,</p>
  
  <pre><code>View.performClick();
  </code></pre>
  
  <p>but it doesn't show the actual press of the button. I've also tried <a href="https://stackoverflow.com/questions/6887674/android-button-programmatic-click">this</a> method,</p>
  
  <pre><code>btn.setPressed(true);
  btn.invalidate();
  </code></pre>
  
  <p>but, it just shows the button being pressed down. I've narrowed it down to this code, which presses down, and releases, but doesn't click. Am I missing something? How can I do a complete click as if though the user was clicking (monkeyrunner is not an option as of right now)</p>
  
  <pre><code>btn = (Button) findViewById(R.id.btn_box);
      Handler handler = new Handler();
      Runnable r = new Runnable() {
          public void run() {
              btn.setPressed(true);
              btn.invalidate();
              Handler handler1 = new Handler();
              Runnable r1 = new Runnable() {
                  public void run() {
                      btn.setPressed(false);
                      btn.invalidate();
  
                  }
              };
              handler1.postDelayed(r1, 1000);
  
          }
      };
      handler.postDelayed(r, 1000);
  </code></pre>