You've learned how to define an options menu an XML resource file, but you can also add items dynamically with Java code. You can also remove or disable menu items programmatically.
- [Instructor] I've already described how to define…an options menu in an XML resource file…but you can also add and manage menu items with Java code.…In this project I already have an options menu,…and it's defined in my menu resource directory,…and it's called menumain.XML.…And it has two items for settings and about.…In the main activity class, I have the on create…options menu method, and that's an override,…a callback method.…It's called automatically by the framework…as the activity starts up and the menu…in being inflated from the XML file.…
Now I'm going to add a bit of code here,…to add another item to the menu.…I'll create the menu item as a Java object.…The menu item class is in the Android dot view package.…I'll name it item, and I'll call menu dot add.…There are a few different method signatures here.…You can pass in a group ID, an item ID,…an order and a character sequence or a string.…Alternatively you can just pass in a string resource ID.…
Now I'm not using groups or categories…so I'm going to pass in a constant for the first…
David also shows how to send and receive broadcast messages that let you exchange data and notifications among the different tiers of your application. He demonstrates how to work with menus and the action bar, add a navigation drawer to a layout, and tackle advanced navigation techniques. Later courses in the Essentials series concentrate on other specific skills you can master.
- Working with events
- Handling events with Java objects and lambda expressions
- Managing navigation
- Sending data to an activity
- Opening other apps with implicit intents
- Sending and receiving broadcast messages
- Working with menus and the action bar
- Adding a navigation drawer
- Advanced navigation techniques
- Removing activities from the back stack