Chapter 10. Building a View
Android comes with many requirements that herald complexity in the user interface: it’s a multiprocessing system that supports multiple concurrent applications, accepts multiple forms of input, is highly interactive, and must be flexible enough to support a wide range of devices now and in the future. The user interface is impressively rich and easy to use, given all that it has to do. But you need to understand how it works in order to use it without crashing your application, making it look awful on some devices, or imposing a performance penalty on the system.
This chapter gives you basic techniques for writing a graphical interface on Android. It explains the architecture of the Android UI toolkit, while showing you in practical terms how to enable and lay out basic interface elements such as buttons and text boxes. It also covers event handling and other critical topics, such as using multiple threads to offload long tasks so that the UI doesn’t freeze.
Android GUI Architecture
The Android environment adds yet another Graphical User Interface (GUI) toolkit to the Java ecosphere, joining AWT, Swing, SWT, and J2ME (leaving aside the web UI toolkits). If you’ve worked with any of these, the Android framework will look familiar. Like them, it is single-threaded, event-driven, and built on a library of nestable components.
The Android UI framework is, like the other UI frameworks, organized around the common Model-View-Controller pattern illustrated in