vii
Table of Contents
Learning Android ........................................................................................................... xix
Prerequisites .......................................................................................................... xix
What’s New in the Third Edition? ............................................................................. xix
How to Use This Book ............................................................................................. xx
How This Book Is Organized .................................................................................... xx
Challenges ..................................................................................................... xxi
Are you more curious? .................................................................................... xxi
Code Style ............................................................................................................. xxi
Typographical Conventions ...................................................................................... xxii
Android Versions ................................................................................................... xxii
The Necessary Tools ..................................................................................................... xxiii
Downloading and Installing Android Studio .............................................................. xxiii
Downloading Earlier SDK Versions ......................................................................... xxiii
A Hardware Device ............................................................................................... xxiv
- Your First Android Application ........................................................................................ 1
App Basics ............................................................................................................... 2
Creating an Android Project ........................................................................................ 3
Navigating in Android Studio ...................................................................................... 8
Laying Out the UI ..................................................................................................... 9
The view hierarchy .......................................................................................... 13
Widget attributes ............................................................................................. 14
Creating string resources ................................................................................... 15
Previewing the layout ....................................................................................... 16
From Layout XML to View Objects ........................................................................... 17
Resources and resource IDs ............................................................................... 18
Wiring Up Widgets .................................................................................................. 21
Getting references to widgets ............................................................................. 22
Setting listeners ............................................................................................... 23
Making Toasts ......................................................................................................... 25
Using code completion ..................................................................................... 26
Running on the Emulator .......................................................................................... 27
For the More Curious: Android Build Process .............................................................. 30
Android build tools .......................................................................................... 31
Challenges .............................................................................................................. 32
Challenge: Customizing the Toast ............................................................................... 32 - Android and Model-View-Controller ............................................................................... 33
Creating a New Class ............................................................................................... 34
Generating getters and setters ............................................................................ 35
Model-View-Controller and Android ........................................................................... 37
Benefits of MVC ............................................................................................. 38
Updating the View Layer .......................................................................................... 39
Updating the Controller Layer ................................................................................... 41
Running on a Device ............................................................................................... 46
Connecting your device .................................................................................... 46
Configuring your device for development ............................................................ 46