Introspection

Sometimes, you know just what you want to do, such as display one of your other activities. Sometimes, you have a pretty good idea of what you want to do, such as view the content represented by a Uri, or have the user pick a piece of content of some MIME type. Sometimes, you're lost. All you have is a content Uri, and you don't really know what you can do with it. For example, suppose you were creating a common tagging subsystem for Android, where users could tag pieces of content - contacts,...

Example

Let's look at an example Linear that shows LinearLayout properties set both in the XML layout file and at runtime. lt xml version 1.0 encoding utf-8 gt lt LinearLayout gt lt RadioGroup android id id orientation android padding 5px gt lt RadioButton android text horizontal gt lt RadioButton android id id vertical android text vertical gt lt RadioGroup gt lt RadioGroup android id id gravity android padding 5px gt lt RadioButton android id id left android text left gt lt RadioButton android id id...

Turn the Radio Up

As with other implementations of radio buttons in other toolkits, Android's radio buttons are two-state, like checkboxes, but can be grouped such that only one radio button in the group can be checked at any time. Like CheckBox, RadioButton inherits from CompoundButton, which in turn inherits from Textview. Hence, all the standard Textview properties for font face, style, color, etc. are available for controlling the look of radio buttons. Similarly, you can call isChecked on a RadioButton to...

Reticle

The reticle is the small circle showing the center of the map. Just as you can set the map center, you can retrieve it by calling getMapCenter on the MapView. This will return a Point reflecting the position of the reticle. The user, in turn, can use the reticle to point at a specific spot, perhaps using the option menu to signal to your activity that it wants some information about that point. Particularly if you will be implementing overlays see below , you will probably want to add the...

Craft the Search Activity

The first thing you are going to want to do if you want to support query-style search in your application is to create a search activity. While it might be possible to have a single activity be both opened from the launcher and opened from a search, that might prove somewhat confusing to users. Certainly, for the purposes of learning the techniques, having a separate activity is cleaner. The search activity can have any look you want. In fact, other than watching for queries, a search activity...

Spin Control

In Android, the Spinner is the equivalent of the drop-down selector you might find in other toolkits e.g., JComboBox in Java Swing . Pressing the left and right buttons on the D-pad iterates over children. Pressing the center button on the D-pad displays, by default, a small list akin to a ListView appears to show a few items at a time, instead of the one-item-at-a-time perspective the unexpanded Spinner itself provides. As with ListView, you provide the adapter for data and child views via...

Pick and Choose

With limited-input devices like phones, having widgets and dialogs that are aware of the type of stuff somebody is supposed to be entering is very helpful. It minimizes keystrokes and screen taps, plus reduces the chance of making some sort of error e.g., entering a letter someplace where only numbers are expected . As shown previously, Editview has content-aware flavors for entering in numbers, phone numbers, etc. Android also supports widgets DatePicker, TimePicker and dialogs...

The Idiosyncrasies

There are a few rules to follow, at least in this milestone edition of the Android toolkit, in order to make these three work together You must give the TabWidget an android id of android id tabs You must set aside some padding in the FrameLayout for the tab buttons more on this below If you wish to use the TabActivity, you must give the TabHost an android id of android id tabhost TabActivity, like ListActivity, wraps a common UI pattern activity made up entirely of tabs into a pattern-aware...

Narrow Receivers

In the examples shown above, the intent filters were set up on activities. Sometimes, tying intents to activities is not exactly what we want Some system events might cause us to want to trigger something in a service rather than an activity Some events might need to launch different activities in different circumstances, where the criteria are not solely based on the intent itself, but some other state e.g., if we get intent X and the database has a Y, then launch activity M if the database...

Settings Preferences and Options Oh My

With your favorite desktop Web browser, you have some sort of settings or preferences or options window. Between that and the toolbar controls, you can tweak and twiddle the behavior of your browser, from preferred fonts to the behavior of Javascript. Similarly, you can adjust the settings of your Webview widget as you see fit, via the WebSettings instance returned from calling the widget's getsettings method. There are lots of options on WebSettings to play with. Most appear fairly esoteric...

Manifest Destiny

Finally, you need to add the service to your AndroidManifest.xml file, for it to be recognized as an available service for use. That is simply a matter of adding a service element as a child of the application element, providing android name to reference your service class. For example, here is the AndroidManifest.xml file for MailBuzz lt activity android name .MailBuzz android label MailBuzz gt lt intent-filter gt lt action gt lt category gt lt intent-filter gt lt activity gt lt service gt lt...