I would like to do something while any hardware button is pressed (not after it is released).I know how to do it with a regular button, but how can I achieve it with a hardware button?
This is the behavior I want to simulate using a hardware button.
button.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
button.setText("Button Pressed");
}
if(event.getAction() == MotionEvent.ACTION_UP){
button.setText("Start"); //finger was lifted
}
return true;
}
});