Changes

Jump to: navigation, search
no edit summary
Create a new project in Android Studio, entering EventExample into the Application name field and ebookfrenzy.com as the Company Domain setting before clicking on the Next button.
On the form factors screen, enable the Phone and Tablet option and set the minimum SDK setting to API 8: Android 2.2 (Froyo). Continue to proceed through the screens, requesting the creation of a blank activity named EventExampleActivity with a corresponding layout and menu resource files named activity_event_exampleand menu_event_example respectively.
== Designing the User Interface ==
[[Image:android_studio_event_example_uiandroid_studio_event_example_ui2.png|The user interface layout for an Android Studio Event handling example app]]
Figure 20-1
Locate and select the activity_event_example.xml file created by Android Studio (located in the Project tool window under EventExample -> app -> src -> main -> res -> layouts) and double click on it to load it into the Designer tool. Switch from Design mode to Text mode using the tab at the bottom of the Designer panel and delete the current content of the file. With a blank canvas, either use Design mode to visually design the user interface from Figure 20-1 (making sure to change the IDs of the Button and TextView objects to @+id/myButton and @+id/myTextView respectively), or directly enter the following XML using Text mode:
<pre>
For the purposes of this example, an onClickListener needs to be registered for the myButton view. This is achieved by making a call to the setOnClickListener() method of the button view, passing through a new onClickListener object as an argument and implementing the onClick() callback method. Since this is a task that only needs to be performed when the activity is created, a good location is the onCreate() method of the EventExampleActivity class.
If the EventExampleActivity.java file is already open within an editor session, select it by clicking on the tab in the editor panel. Alternatively locate it within the Project tool window by navigating to (EventExample -> app -> src -> main -> java -> com.ebookfrenzy.eventexample -> EventExampleActivity) and double click on it to load it into the code editor. Once loaded, locate the template onCreate() method and modify it to obtain a reference to the button view, register the event listener and implement the onClick() callback method:
<pre>

Navigation menu