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,
 Mike

--~--~---------~--~----~------------~-------~--~----~



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:

 http://preview.tinyurl.com/5ebu4s 

LinearLayout8.java in the SDK's ApiDemos shows the use of the options 
menu. I'm sure there are any number of tutorials up on anddev.org as 
well. The code bundle at  http://commonsware.com/Android/ also has sample  
code for both the options menu and the context menu (a.k.a., "long tap" 
menu).

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)
 http://commonsware.com 
_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.

Regards,
Ashok





--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Modaco custom ROM with HTC Sense ( Desire ROM )

Wihhhh

Nexus one gw coba selingkuh pake ported HTC Desire Rom. Smooth banget...
mungkin karena spec htc desire saingan n1 kali ya nantinya

Yang signifikan
1. Seneng liat browser nya ber flash
2. Network Bisa pilih wcdma-gsm atau gsm only atau wcdma only
3. Live wallpaper smooth
4. UI nya oke... improved sense ui.

Stay disini dulu. So far belum ada FC atau bug.

Sorry kalo dah basi. Baru buka2x xda-developers lagi soalnya...

Wekekeke

Thanks

-- 
"Indonesian Android Community [id-android]" 

2. Non-parallel construction of DatePicker and TimePicker

I was surprised and dismayed to discover that the DatePicker and
TimePicker classes, which are of parallel construction in almost every
way, differ in one significant way.  There is no
setOnDateChangedListener(...) method in DatePicker while there is a
setOnTimeChangedListener(...) method in TimePicker.  For two classes
that parallel one another in every other way, including the appearance
and operation of their corresponding Views, why do they diverge in
this fairly important aspect?   I eventually discovered that there is
a way to set the OnDateListener through the init(...) method, but COME
ON!  Was this just an oversight on Google's part?  I hope that they
fix this in a coming release.

-- 

3. GPS code works in HTC machines but fails in MOTO's

4. Harga Nexus one

5. OOT : miring gak jadi dulu

6. File system access triggers / listener on Android devices

7. Debian on NexusOne woow