14.01.2013 Views

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

}<br />

super.onCreate(icicle);<br />

CompassView cv = new CompassView(this);<br />

setContentView(cv);<br />

cv.setBearing(45);<br />

Chapter 4: Creating User Interfaces<br />

To use the same control within a layout resource, specify the fully qualifi ed class name when you create<br />

a new node in the layout defi nition, as shown in the following XML snippet:<br />

<br />

You can infl ate the layout and get a reference to the CompassView as normal, using the following code:<br />

@Override<br />

public void onCreate(Bundle icicle) {<br />

super.onCreate(icicle);<br />

setContentView(R.layout.main);<br />

CompassView cv = (CompassView)this.findViewById(R.id.compassView);<br />

cv.setBearing(45);<br />

}<br />

Creating and Using Menus<br />

Menus offer a way to expose application functions without sacrifi cing valuable screen space. Each<br />

Activity can specify its own Activity menu that’s displayed when the device’s menu button is pressed.<br />

Android also supports context menus that can be assigned to any View within an Activity. A View’s<br />

context menu is triggered when a user holds the middle D-pad button, depresses the trackball, or longpresses<br />

the touch screen for around 3 seconds when the View has focus.<br />

Activity and context menus support submenus, checkboxes, radio buttons, shortcut keys, and icons.<br />

Introducing the Android Menu System<br />

If you’ve ever tried to navigate a mobile phone menu system using a stylus or trackball, you’ll know<br />

that traditional menu systems are awkward to use on mobile devices.<br />

To improve the usability of application menus, Android features a three-stage menu system optimized<br />

for small screens:<br />

The Icon Menu<br />

❑ This compact menu (shown in Figure 4-4) appears along the bottom of the<br />

screen when the Menu button is pressed. It displays the icons and text for up to six Menu Items<br />

(or submenus).<br />

99

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!