Skip to Content
Android 9 Development Cookbook - Third Edition
book

Android 9 Development Cookbook - Third Edition

by Rick Boyer
October 2018
Intermediate to advanced
464 pages
15h 17m
English
Packt Publishing
Content preview from Android 9 Development Cookbook - Third Edition

How it works...

We created an override for onCreateOptionsMenu(), just like we did in the previous recipe, Creating an options menu. But instead of inflating an existing menu resource, we created the menu using the Menu.add() method. Since we want to modify the menu items later as well as respond to the menu item events, we defined our own menu IDs and passed them to the add() method. The onOptionsItemSelected() object is called for all the menu items, so we get the menu ID and use a switch statement based on the ID. We return true if we are handling the menu event, otherwise we pass the event to the super class.

Changing the menu occurs in the onPrepareOptionsMenu() method. To simulate an external event, we created a button to toggle a Boolean ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Android Application Development Cookbook - Second Edition

Android Application Development Cookbook - Second Edition

Rick Boyer, Kyle Mew
Android High Performance Programming

Android High Performance Programming

Enrique López Mañas, Diego Grancini
Android Things Projects

Android Things Projects

Francesco Azzola

Publisher Resources

ISBN: 9781788991216Supplemental Content