How parameters are passed to event handler methods

  • Replies:0
  • OpenNot stickiedUnanswered
  • Forum posts: 1

Jul 7, 2018, 10:01:49 AM via Website

Hi guys,

I use Java and Android Studio for developing apps. I use them since a while but I have still a doubt about the Android Events Mechanism and the way parameters required by the event handlers arrive to them. The event handlers are methods, more specifically callbacks, and can receive parameters. Usually, when you call a method that requires parameters you have to pass them to it but, in the case of event handlers, it seems that something obscure happens because the parameters are passed “automatically” to the callback. I tried to find explanations on Internet and books but with no results. For example, the View type parameter required by the onClick event handler, how is it passed? from where? I perfectly know that this parameter represents the object on which I have clicked but I want to know when and where the passing happens.
Another example: the onLocationChanged callback requires an input parameter of type Location... blah blah blah

Could you please explain in a clear and detailed way how the mechanism works? How this “automatic” parameter passage works? If I would to create a custom callback that works in this way, how could I accomplish this?

Thanks
F

Be the first to answer

Recommended articles