Skip to Content
Learning Android
book

Learning Android

by Marko Gargenta
March 2011
Beginner
266 pages
6h 55m
English
O'Reilly Media, Inc.
Content preview from Learning Android

Chapter 6. Android User Interface

In this chapter, you will learn how to build a user interface in Android. You will create your first Activity, learn how to create an XML layout for it, and see how to connect it to Java. You will learn about Views (aka 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. One is declarative, and the other one is programmatic. 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 what-you-see-is-what-you-get (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, ...

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

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Learning Android, 2nd Edition

Learning Android, 2nd Edition

Marko Gargenta, Masumi Nakamura
Android Cookbook

Android Cookbook

Ian F. Darwin

Publisher Resources

ISBN: 9781449304881Errata Page