Solved

menu example

Posted on 2012-03-27
5
301 Views
Last Modified: 2012-03-27
I am having trouble finding menu examples that work.
I copied the code and download menu examples without success.

I am after complete menu examples to learn about menus.
0
Comment
Question by:jagguy
  • 3
  • 2
5 Comments
 

Author Comment

by:jagguy
ID: 37770878
I got one to work .

when does this code run because there is no call to this. Is it when you hit menu on the emulator?
 
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
    }
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37773127
http://developer.android.com/guide/topics/ui/menus.html

To specify the options menu for an activity, override onCreateOptionsMenu() (fragments provide their own onCreateOptionsMenu() callback). In this method, you can inflate your menu resource (defined in XML) into the Menu provided in the callback. For example:
(here exactly the same code as yours quoted above)

If you've developed your application for Android 2.3.x and lower, the system calls onCreateOptionsMenu() to create the options menu when the user opens the menu for the first time. If you've developed for Android 3.0 and higher, the system calls onCreateOptionsMenu() when starting the activity, in order to show items to the action bar.
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 37773225
>when does this code run because there is no call to this.
All these are callback functions - you prepare the contents of those but you'll not see any calls to them in your code - they are called by the "container" (in this case it would be Android opertaing system I giess), which knows that at some apparopriate moment of the life cycle of applaication or part of it cvertain method needs to be called.
0
 

Author Comment

by:jagguy
ID: 37774330
Thanks for the information.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37774374
Yes, AdapterView.OnItemCLickListener - it locates and imports both these types for me based on that code which you pointed to
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A short article about problems I had with the new location API and permissions in Marshmallow
The case of the missing phone talks about the way a small electronic gadget (the mobile phone) has penetrated into our lives and has made us addicted to it.
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now