How to know if a button is being pressed or released?
<p>I have a little problem when I try to run my Android application. The problem occurs when I push &amp; release a button on my main View. The application is to behave like a portophone (push the button to talk, release to stop).</p>

<p>To notify that the button is pressed or released, I've tried 2 options:
- Adding an onClickListener,
- Adding an onTouchListener.</p>

<p>The first only looks for the button being pressed, so it's not a viable solution. The second solution is able to differentiate between pushed &amp; released, so it's the one I'm using now. The code looks like this:</p>

<pre><code>// Initialise handler for Push To Talk button
    Button button = (Button) findViewById(R.id.buttonPTT);
    button.setOnTouchListener(new OnTouchListener(){
        @Override
        public boolean onTouch(View v, MotionEvent me){
            switch(me.getAction()){
            case MotionEvent.ACTION_DOWN:
                Toast.makeText(getApplicationContext(), "PTT pressed", Toast.LENGTH_LONG).show();
                // TODO: Activate Push To Talk
                break;
            case MotionEvent.ACTION_UP:
                Toast.makeText(getApplicationContext(), "PTT released", Toast.LENGTH_LONG).show();
                // TODO: End Push To Talk
                break;
            }
            return false;
        }
    });
</code></pre>

<p>The problem lies in the ACTION_UP case of the switch. While running, it will only work when you press the button, move the cursor/finger/etc, and then release the button. What I want it to do is press it, and being able to release it without having to move my cursor/finger/etc.</p>

<p>Anybody have any ideas?</p>
