capture any event in an activitty [closed]

1

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.

    
asked by diego alejandro franco osorio 25.04.2016 в 15:31
source

1 answer

1

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;
}
    
answered by 25.04.2016 / 18:01
source