Chapter 2. Building Interactive Apps: Apps That Do Something

image

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

And in this chapter, you’ll see how you can make your apps more interactive. You’ll discover how to add an OnClickListener to your activity code so that your app can listen to what the user’s doing, and make an appropriate response. You’ll find out more about how to design layouts, and you’ll learn how each UI component you add to your layout is derived from a common View ancestor. Along the way, you’ll discover why String resources are so important for flexible, well-designed apps.

Let’s build a Beer Adviser app

When you create an Android app, you’re usually going to want it to do something.

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

image

Here’s how the app will be structured:

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

    It includes three UI components:

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

    • A button that, when clicked, will return a selection of beers ...

Get Head First Android Development, 3rd 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.