O'Reilly logo

Learning Android, 2nd Edition by Masumi Nakamura, Marko Gargenta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. Android User Interface

In this chapter, you will learn how to build a user interface in Android. You will create your first activity, create an XML layout for it, and see how to connect it to your Java code. You will learn about views (a.k.a. widgets) and layouts, and learn how to handle Java events, such as button clicks. Additionally, you’ll add support for a Twitter-like API into your project as an external .jar file so your app can make web service calls to the cloud.



By the end of this chapter, you will have written your own Twitter-like Android app. The app will feature a single screen that will prompt the user for her current status update and post that update online.

Two Ways to Create a User Interface

There are two ways to create a user interface (UI) in Android: declaratively and programmatically. They are quite different but often are used together to get the job done.

Declarative User Interface

The declarative approach involves using XML to declare what the UI will look like, similar to creating a web page using HTML. You write tags and specify elements to appear on your screen. If you have ever handcoded an HTML page, you did pretty much the same work as creating an Android screen.

One advantage of the declarative approach is that you can use WYSIWYG tools. Some of these tools ship with the Eclipse Android Development Tools (ADT) extension, and others come from third parties. Additionally, XML is fairly human-readable, and even people who are unfamiliar with ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required