Possible Duplicate:
onPress/onRelease in Android
When a user holds a button the button changes color, and when the user leaves the button, the button returns to it's normal state.
Is there an event that captures this ?
I tried searching for something like button.onStateChanged, but no luck..
EDIT: When the user long clicks I want to start the autoincrement
// Auto increment for a long click
increment.setOnLongClickListener(new View.OnLongClickListener() {
public boolean onLongClick(View a) {
autoIncrement = true;
repeatUpdateHandler.removeCallbacks(mRepeatUpdateHandler);
repeatUpdateHandler.post(mRepeatUpdateHandler);
return false;
}
});
And when the user leaves the button with his finger I want to stop the autoincrement
increment.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP && autoIncrement) {
//Stop autoincrement
repeatUpdateHandler.removeCallbacks(mRepeatUpdateHandler);
autoIncrement = false;
}
return false;
}
});
This is the handler:
RepetetiveUpdater mRepeatUpdateHandler = new RepetetiveUpdater();
....
class RepetetiveUpdater implements Runnable {
public void run() {
if (autoIncrement) {
increment();
repeatUpdateHandler.postDelayed(new RepetetiveUpdater(),
REPEAT_DELAY);
} else if (autoDecrement) {
decrement();
repeatUpdateHandler.postDelayed(new RepetetiveUpdater(),
REPEAT_DELAY);
}
}
}
But this only works when the user lifts his finger above the button, when he drags it to somewhere else on the screen, the counter keeps running, any ideas?