tags:

views:

188

answers:

1

Is there a way to get an onButtonDown or onButtonUp event for a soft button (i.e. not a physical hardware button, but a button on the screen)? I have a button on the screen that I want the user to hold down for X seconds. To do this I need to capture the buttonDown and buttonUp events separately.

Thanks,

Bret

A: 
yourButton.setOnTouchListener( yourListener );

public boolean onTouch( View yourButton , MotionEvent theMotion ) {
    switch ( theMotion.getAction() ) {
    case MotionEvent.ACTION_DOWN: break;
    case MotionEvent.ACTION_UP: break;
    }
    return true;
}
drawnonward
Awesome! Thanks, drawnonward! I went in the direction of onLongClick since it seemed most intuitive (I was wrong) ;-). I tried to upvote this, but I'm new here and don't have enough reputation points. Thanks again!
Bret