1

Recently I was reading about onTouch and SimpleGesturesListener .While reading I came to this line:-

true if the event is consumed else false

Now I am quite confused and have some questions as follows :

1) What does consumed means in simple way ?

2) In this example :

  public boolean onTouch(View arg0, MotionEvent arg1) {
                // TODO Auto-generated method stub
                float currentX,currentY;
                int action=arg1.getAction();

                 if (gestureDetector.onTouchEvent(arg1)) {
                     // single tap

                     return true;
                 } 

If I make it return false what will actually happen .Will it means that event is not consumed ?

2) In the above code if I make return null and also in onTouch if I make the same what will happen ?

Please answer I am a beginner .

utkarsh dubey
  • 141
  • 2
  • 14
  • 4
    Consumed means the 'event' will not be propagated to anybody else waiting for it. This can essentially be understood by taking the example of parent-child scenarios: touch events are firstly initiated on the parent which can decide to pass on the event to the child or consume it themselves. If consumed, the child will not even be aware of the occurrence of any such event. – Shaishav Sep 09 '16 at 08:17
  • @Shaishav `View.OnTouchListener` has nothing to do with passing the events to child views: you can setup `View.OnTouchListener` on parent view returning `true` in its `onTouch` method (consuming the events) and still the events are passed to the child views – pskink Sep 09 '16 at 08:34
  • To answer (1): This is related to the [producer-consumer problem](https://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem). Normally it is used in design patterns such as "chain of responsibility". When you have a GUI hierarchy an event will be propagated higher up until an object `A` decides to do something with the event. Then `A` will then `consume` it, so that all the listeners to `A` know that this event is not available anymore. The concept is a bit abstract so I suggest you read a little about the producer-consumer problem. – patrik Sep 09 '16 at 08:35

0 Answers0