18

In blackberry we can override keyChar() method and capture the keypress event or we can register onKeyPressListener. i know, onKeyListener is observer pattern.

In android also there is a KeyEvent.callback and onKeyListener

Both are events why we no need to register for keyChar event. what is the difference between both pattern?

14

There can be many listeners for some type of event, but only one callback.

  • In android we can set only one OnClickListener to a view. – Vivart Jun 17 '11 at 8:28
  • 2
    It's quite possible that their definition of "listener" doesn't match that of other products. Usualy, you don't have a "setFooBarListener()" method, but an "addFooBarListener()" method. – user281377 Jun 17 '11 at 8:31
  • 3
    Another distinction could be that callback means a function (or closure or delegate), while listener is an object of a class that implements the corresponding Listener interface. – user281377 Jun 17 '11 at 8:42
  • Vivart: doesn't matter, my answer isn't that good anyway – user281377 Jun 17 '11 at 17:17
-5

I suppose that you have an application which use a library:

Listener: Library runs some code on its data, but, the code is implemented on Application.

Callback: Application runs some code on its data, however, the code is implemented on Library.

Because library can't see the application, so there is no way to instead Listener for that case.

Of course Application can see the library, but sometimes library wants to hide it's code, and helps application to make sense with it

protected by gnat Nov 4 '17 at 12:23

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.