A (175)

(Tuis.) #1
CHAPTER 14: Android Content Providers: Providing Data to Applications 521

Next, right-click on the main.xml Menu object definition file in the /res/menu folder and add a
contact_galaxy MenuItem object. To do this, you use an tag that is configured similar to
your other menu items, as shown in Figure 14-8.


Figure 14-7. Add a constant named contact_galaxy with the data value Contact Galaxy Ruler


Figure 14-8. Add a MenuItem object using tag with ID contact_galaxy, reference contact_galaxy


Adding a Menu Intent in the MainActivity Class


Now that your MenuItem object is defined using XML, you can reference it in your
onOptionsItemSelected( ) event handling structure in your MainActivity.java class. You will do this
so that your users can switch over to the ContactGalaxy Activity subclass. Add a case statement for
R.id.contact_galaxy and create a new Intent object named dataIntent using the Java new keyword.

Free download pdf