Lecture 10

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 10

Mobile Application Development

Lecture#10
How to develop a very simple Application
Event Driven Programming
• A UI event is an action that is triggered by the user interacting with UI
• A button pressed or released
• A key is processed or released
• An area of touch screen is touched.
• Gestures
Event Driven Programming
Android Event Handling
• Events are a useful way to collect data about a user's interaction with interactive
components of Applications. Like button presses or screen touch etc. The Android
framework maintains an event queue as first in, first out (FIFO) basis.
• You can capture these events in your program and take appropriate action as per
requirements.
Event Handling (Concepts)
• There are following three concepts related to Android Event Management.
• Event Listeners − An event listener is an interface in the View class that contains a
single callback method. These methods will be called by the Android framework when
the View to which the listener has been registered is triggered by user interaction with
the item in the UI.
• Event Listeners Registration − Event Registration is the process by which an Event
Handler gets registered with an Event Listener so that the handler is called when the
Event Listener fires the event.
• Event Handlers − When an event happens and we have registered an event listener for
the event, the event listener calls the Event Handlers, which is the method that actually
handles the event.
Event Listener
• View class defines the java interface that contains a
single callback method
• Activity implements the interface callback methods
• Triggered by user interaction
• Several callbacks methods are availabale
• onClick()
• onTouch()
• onFocusChange()
• Etc.
Event Listeners & Event Handlers
Event Listeners & Event
Handlers(Cont.)
Event Listeners Registration
• Event Registration is the process by which an Event Handler gets registered with an Event Listener
so that the handler is called when the Event Listener fires the event.
• Top Three Ways to Register an Event are:
1) Using an Anonymous Inner Class
2) Activity class implements the Listener interface.
3) Using Layout file activity_main.xml to specify event handler directly.

You might also like