Chapter 2. Building Interactive Apps: Apps That Do Something

Most apps need to respond to the user in some way.

In this chapter, you’ll see how you can make your apps a bit more interactive. You’ll learn how to get your app to do something in response to the user, and how to get your activity and layout talking to each other like best buddies. Along the way, we’ll take you a bit deeper into how Android actually works by introducing you to R, the hidden gem that glues everything together.

Let’s build a Beer Adviser app

In Chapter 1, you saw how to create an app using the Android Studio New Project wizard, and how to change the text displayed in the layout. But when you create an Android app, you’re usually going to want the app to do something.

In this chapter, we’re going to show you how to create an app that the user can interact with: a Beer Adviser app. In the app, users can select the types of beer they enjoy, click a button, and get back a list of tasty beers to try out.

Here’s how the app will be structured:

  1. The layout specifies what the app will look like.

    It includes three GUI components:

    • A drop-down list of values called a spinner, which allows the user to choose which type of beer they want.

    • A button that when pressed will return a selection of beer types.

    • A text field that displays the types of beer.

  2. The file strings.xml includes any String resources needed by the layout—for example, ...

Get Head First Android Development, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.