@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
final EditText number = (EditText)findViewById (R.id.number);
Button dial = (Button)findViewById(R.id.dial);
dial.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
String toDial = 'tel:' + number.getText().toString ();
startActivity(new Intent (Intent.ACTION_DIAL,
Uri.parse(toDial)));
}
});
}
}
The activity’s own UI is not that impressive as shown in Figure 35-1.

Figure 35-1.
However, the dialer you get from clicking the dial button is better, showing you the number you are about to dial in Figure 35-2.

Figure 35-2.
CHAPTER 36
Searching with SearchManager
One of the firms behind the Open Handset Alliance — Google — has a teeny-weeny Web search service, one you might have heard of in passing. Given that, it’s not surprising that Android has some built-in search capabilities. Specifically, Android has baked in the notion of searching not only on the device for data, but over the air to Internet sources of data. Your applications can participate in the search process by triggering searches or perhaps by allowing your application’s data to be searched.
Note that this is fairly new to the Android platform, and so some shifting in the APIs is likely.
Hunting Season
There are two types of search in Android: local and global. Local search searches within the current application; global search searches the Web via Google’s search engine. You can initiate either type of search in a variety of ways, including the following:
• You can call onSearchRequested()
from a button or menu choice, which will initiate a local search (unless you override this method in your activity).
• You can directly call startSearch()
to initiate a local or global search, including optionally supplying a search string to use as a starting point.
• You can elect to have keyboard entry kick off a search via setDefaultKeyMode()
, for either local search (setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL)
) or global search (setDefaultKeyMode(DEFAULT_KEYS_SEARCH_GLOBAL)
).
In either case, the search appears as a set of UI components across the top of the screen, with your activity blurred underneath it (see Figures 36-1 and 36-2).

Figure 36-1.

Figure 36-2.
Search Yourself
Over the long haul, there will be two flavors of search available via the Android search system:
• Query-style search, where the user’s search string is passed to an activity that is responsible for conducting the search and displaying the results
• Filter-style search, where the user’s search string is passed to an activity on every key press, and the activity is responsible for updating a displayed list of matches
Since the latter approach is under heavy development right now by the Android team, let’s focus on the first one.
Craft the Search Activity
The first thing you’ll 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 looks, walks, and talks like any other activity in your system.
All the search activity needs to do differently is check the intents supplied to onCreate()
(via getIntent()
) and onNewIntent()
to see if one is a search, and, if so, to do the search and display the results.
For example, let’s look at the Search/Lorem
sample application (available in the Source Code section of http://apress.com). This starts off as a clone of the list-of-lorem-ipsum-words application that we first built back when showing off the ListView
container in Chapter 8, then with XML resources in Chapter 19. Now we update it to support searching the list of words for ones containing the search string.
The main activity and the search activity share a common layout: a ListView
plus a