Respoding to Menu button click?

by MBraude » Wed, 25 Jun 2008 07:52:09 GMT

Sponsored Links
 Hi Everybody,

I'm sure this is an easy thing to do, but I haven't run into an
example yet that responds to the user clicking the Menu button on the
phone.  I'd like to be able to show / hide some things based on this
click event.  What's the easiest way to do this?

Thanks very much,


Respoding to Menu button click?

by Mark Murphy » Wed, 25 Jun 2008 11:19:56 GMT


The Menu button pops up the options menu for the activity. To fill in 
that menu, you need to implement onCreateOptionsMenu() in your activity 
and populate the supplied Menu object, per the docs: in the SDK's ApiDemos shows the use of the options 
menu. I'm sure there are any number of tutorials up on as 
well. The code bundle at also has sample  
code for both the options menu and the context menu (a.k.a., "long tap" 

I think there was an earlier post in one of these Google Groups from a 
Googler that indicated using the Menu button for anything else other 
than the options menu is uncool.

Mark Murphy (a Commons Guy) 
_The Busy Coder's Guide to Android Development_ -- Available Now!


Sponsored Links

Respoding to Menu button click?

by Ashok Singal » Wed, 25 Jun 2008 19:17:36 GMT

 Hi Mike,

If you could go through the Tutorial Exercise 2nd, you will find that there
are two functions that Android has provided for managing items in the Menu
Control as following:

1. onCreateOptionsMenu(): You can create your items in Menu.

2. onMenuItemSelected(): What action needs to be taken when a particular
menu item is selected? This function gets an Item parameter so when you will
call item.getID(), it will return a particular menu item selected by the
user and you can handle that accordingly.

I hope that this answers to your question.



Other Threads

1. App not compatible. How to detect which feature/code is incompatible


I wrote an app and since a few days I receive multiple reports that
the Android Market says my app isn't compatible with their phone. It's
only one specific phone, Motorola Defy. I have no idea what is
incompatible because my app doesn't use anything {*filter*}. How can a
developer know what is incompatible without actually having that type
of phone?



2. how to get focus(selection) to listactivity?


i am using listactivity to diaplay list.and here is my xml code for
                        android:listSelector = "@drawable/list_pressed"/>

i am not getting focus anyway. list_pressed is my selector xml.



3. Locate Zoom Controls (x,y) in MapView?

4. uninstalling packages/ APK's in C

5. How to change appearance of the ContextMenu

6. service send information to Activity

7. ActionBar.setCustomView doesn't seem to work