ptg7068951
366 HOUR 24:Writing Android Apps
20: public voidprocessClicks(View display) {
21: Intent action;
22: int id = display.getId();
23: switch(id) {
24: case(R.id.phonebutton):
25: Log.i(TAG, “Making call”);
26: action = new Intent(Intent.ACTION_DIAL,
27: Uri.parse(“tel:202-456-1111”));
28: startActivity(action);
29: break;
30: case(R.id.webbutton):
31: Log.i(TAG, “Loading browser”);
32: action = new Intent(Intent.ACTION_VIEW,
33: Uri.parse(“http://whitehouse.gov”));
34: startActivity(action);
35: break;
36: case(R.id.mapbutton):
37: Log.i(TAG, “Loading map”);
38: action = new Intent(Intent.ACTION_VIEW,
39: Uri.parse(“geo:0,0?q=White House, Washington, DC”));
40: startActivity(action);
41: break;
42: default:
43: break;
44: }
45: }
46: }
Save the file when you’redone. It should compile successfully (something
Eclipse does automatically)—if not, the familiar red X’s appear in the Package
Explorer, identifying the files in the project where the errors were found.
When there are no errors, you’re almost ready to run the app.
You must create a newdebug configuration for the project first:
- Click the arrow next to the Debug button in the main Eclipse toolbar,
then choose Debug Configurations. The Debug Configurations dialog
opens. - Double-click Android Application in the left pane. Anew
configuration called New_configuration (1)is created. - Enter LeaderDebugas the Name.
- Click the Browse button, choose the project Leader, and click OK.
- Click the Target tab to bring it to the front.
LISTING 24.2 Continued