menu example

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.
Who is Participating?
for_yanConnect With a Mentor Commented:
>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.
jagguyAuthor Commented:
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?
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(, menu);
        return true;

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.
jagguyAuthor Commented:
Thanks for the information.
Yes, AdapterView.OnItemCLickListener - it locates and imports both these types for me based on that code which you pointed to
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.