title: Click, Press and Release event on Button
body: <p>How can I detect clicked, pressed and released states of a Button. I want to perform different functions on these states. On click I want to call function1, on press I want to call function2 and on receive I want to call function3.</p>
  
  <p>We can detect click state using <code>View.OnClickListener</code>. We can detect Pressed and Released states of a Button using <code>View.OnTouchListener</code> and handling <code>ACTION_DOWN</code> and <code>ACTION_UP</code>. I am able to detect these states individually, however, not together.</p>
  
  <p>Below is code for OnCLickListener.</p>
  
  <pre><code>button.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              System.out.println(" clicked ");
          }
      });
  </code></pre>
  
  <p>Below is code for OnTouchListener.</p>
  
  <pre><code>button.setOnTouchListener(new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
              switch(event.getAction()) {
                  case MotionEvent.ACTION_DOWN:
                      System.out.println(" pressed ");
                      return true;
                  case MotionEvent.ACTION_UP:
                      System.out.println(" released ");
                      return true;
              }
              return false;
          }
      });
  </code></pre>
  
  <p>When I set click and touch listeners on a Button, Click event never gets called. Instead I receive pressed and released state.</p>
  
  <p>How can I handle these three states together?</p>
  
  <p>EDIT:</p>
  
  <p>I added the OnClickListener and OnTouchListener code I have used.</p>