-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Android Application Development Cookbook
By :

Almost every application needs to recognize and respond to basic events such as clicks and long-presses. It's so basic, in most of the recipes, we use the XML onClick
attribute, but the more advanced listeners require setting up through code.
Android provides an Event Listener interface for receiving a single notification when certain actions occur, as shown in the following list:
onClick()
: It's called when a View is pressed
onLongClick()
: It's called when the View is long-pressed
onFocusChange()
: It's called when the user navigates to or from the View
onKey()
: It's called when a hardware key is pressed or released
onTouch()
: It's called when a touch event occurs
This recipe will demonstrate responding to the click event, as well as the long-press event.
Create a new project in Android Studio and call it: PressEvents
. Use the default Phone & Tablet options and select Empty Activity when prompted for the Activity Type.
Change the font size
Change margin width
Change background colour