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 see how you can 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.
You’re going to build a Beer Adviser app
In the Chapter 1, you saw how to create a basic 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: we’ll be creating 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:
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 ...