I would like to know how I can capture an event (either a click or tap on the screen something that generates an action) anywhere in a Activity
. This in order to verify first if something is activated to let the action continue or stop it.
I would like to know how I can capture an event (either a click or tap on the screen something that generates an action) anywhere in a Activity
. This in order to verify first if something is activated to let the action continue or stop it.
If you want to detect a click in a view (TextView, Button, etc) you only detect the click through a OnTouchListener
:
myView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//Aquí muestras información, el clic de la vista fue efecutado.
return false;
}
});
But what you want to do, you can do it with a GestureListener or simply by implementing this method within your activity:
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
super.dispatchTouchEvent(ev);
Log.i(TAG, "Se ha realizado un click dentro de la Activity");
return false;
}