Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is an event listener? Give an example. Solution To handle an event you must

ID: 3657426 • Letter: W

Question

What is an event listener? Give an example.

Explanation / Answer

To handle an event you must implement an event listener interface, which contains one or more event handler methods. When an event is triggered by a control, it calls the appropriate event handler to notify the registered listener about the event. For example, when the user touches a control, the control calls the OnTouchPressed() event handler of the Osp::Ui::ITouchEventListener interface. When the user releases the touch, the OnTouchReleased() event handler is called. To register an instance of the ITouchEventListener interface, you must use the AddTouchEventListener() method. / MyForm.h class MyForm: public Osp::Ui::Controls::Form, public Osp::Ui::ITouchEventListener { // Required declarations }; // MyForm.cpp result MyForm::OnInitializing(void) { result r = E_SUCCESS; Button* pButton = new Button; pButton->Construct(Rectangle(50, 50, 150, 150), L"Button"); // MyForm implements the ITouchEventListener interface pButton->AddTouchEventListener(*this); return r; } The following list introduces some of the event listeners defined by the bada platform: Key event listener The Osp::Ui::IKeyEventListener interface consists of a collection of event handlers related to hard key events. For example, when the user short presses the Side Up key, the OnKeyPressed() event handler is called, followed by the call to the OnKeyReleased() event handler. The key events are always forwarded to the UI control with the key focus. Use the Osp::Ui::KeyEventManager class to add the key event listener for your application, and the UI control's SetFocus() method to give the key focus to the correct UI control. Touch event listener The ITouchEventListener interface is used to receive touch-related events. When the user touches a control, the control calls the OnTouchPressed() event handler. Similarly, when the user releases the touch, the OnTouchReleased() event handler is called. Do not handle touch events directly when the control defines semantic events, such as action events (Osp::Ui::IActionEventListener), which are triggered when the user presses a control, such as a button. For supporting the custom multi-touch gestures, use the Osp::Ui::Touch class. Drag and drop event listener The Osp::Ui::IDragDropEventListener interface is used to receive drag and drop events. Any class that processes drag and drop events can implement this interface. The class instance is registered with a UI control using the control's AddDragDropEventListener() method. When a drag and drop event occurs, either the OnTouchDragged() or OnTouchDropped() event handler of that instance is invoked. When control A is dragged and dropped onto control B, the following sequence of events occurs: The touch-and-drag event is sent to control A and the OnTouchDragged() event handler is called because of the IDragDropEventListener instance that has been added to the control A. In this case, the values of the startPosition and currentPosition parameters are the same. When control A is dropped onto control B, the OnTouchDropped() event handler of control A's IDragDropEventListener instance is called. The currentPosition parameter defines the position coordinates of the drop relative to control A. Finally, the OnTouchDropped() event handler of control B's IDragDropEventListener instance is called. The currentPosition parameter equals the position coordinates of the drop relative to control B. For control B to identify whether control A is dropped onto it, control B must check whether the current position of the drop falls within its boundaries. Touch mode changed event listener The Osp::Ui::ITouchModeChangedEventListener interface is used to receive touch mode change events. It defines a single event handler, OnTouchModeChanged(). The event handler notifies the application when the device enables or disables the touch mode (for example, when the user switches from touching the screen to pressing the hardware keyboard keys, or back). For touch-screen-only devices, this event is not generated. Focus event listener The Osp::Ui::IFocusEventListener interface is used to receive focus events. When a control gains key focus, the OnFocusGained() event handler is called. Similarly, when the control losses key focus, the OnFocusLost() event handler is invoked.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote