Chapter 2. Building Interactive Apps: Apps That Do Something
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.
Here’s how the app will be structured:
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
A text view that displays ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access