Beginning Android 2
Format: PDF / Kindle (mobi) / ePub
The Android development platform, created by Google and the Open Handset Alliance, is a platform in its truest sense, encompassing hundreds of classes beyond the traditional Java classes and open source components that ship with the SDK.
With Beginning Android 2, you’ll learn how to develop applications for Android 2.x mobile devices, using simple examples that are ready to run with your copy of the software development kit. Author, Android columnist, writer, developer, and community advocate Mark L. Murphy will show you what you need to know to get started programming Android applications, including how to craft graphical user interfaces, use GPS, and access web services.
on the user’s selection. Figure 6-2 shows the result when the layout demo is first launched inside the emulator. CHAPTER 6: Working with Containers Figure 6-2. The LinearLayoutDemo sample application, as initially launched If we toggle on the vertical radio button, the top RadioGroup adjusts to match, as shown in Figure 6-3. Figure 6-3. The same application, with the vertical radio button selected If we toggle the center or right radio button, the bottom RadioGroup adjusts to match, as
always stick to the original side from which it opened. This means that if you want the drawer to always open from the same side, as the launcher does, you will need separate layouts for portrait versus landscape, a topic discussed in Chapter 20. Other Good Stuff Android offers AbsoluteLayout, where the contents are laid out based on specific coordinate positions. You tell AbsoluteLayout where to place a child in precise x and y coordinates, and Android puts it that location, no questions asked.
elements. The latter represents a collection of menu items that can be operated upon as a group. Submenus are specified by adding a menu element as a child of an item element, using this new menu element to describe the contents of the submenu. If you want to detect when an item is chosen, or to reference an item or group from your Java code, be sure to apply an android:id, just as you do with View layout XML. Menu Options and XML Inside the item and group elements, you can specify
need to save their state more frequently than you might expect. Then, when the activity restarts, the activity should get its former state back, so it can restore the activity to the way it appeared previously. 169 170 CHAPTER 16: Handling Activity Life Cycle Events Saving instance state is handled by onSaveInstanceState(). This supplies a Bundle, into which activities can pour whatever data they need (e.g., the number showing on the calculator’s display). This method implementation needs to
filters defined, courtesy of the Android application-building script (activityCreator or the IDE equivalent). They look something like this: