Context Menu

by MarQuel Middleton » Sun, 13 Sep 2009 06:20:09 GMT

Sponsored Links
 Im trying to set my application menus up and i cant seem to do it  can
someone help me out i would really appreciate it im real confused!! I
just want to be able to press my exit button and it close the app or
something of that nature.


import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class LimeDroid extends Activity {
    /** Called when the activity is first created.

     * @return */

        public boolean onCreateOptionsMenu(Menu menu){

                MenuInflater inflater = getMenuInflater();

                inflater.inflate(, menu);

                return true;


         public boolean onOptionsItemSelected(MenuItem item) {

    public void onCreate(Bundle savedInstanceState) {

        Intent intent = new Intent("Reverse");
        String variableToPass = null;
                intent.putExtra("INFO_TO_PASS", variableToPass);




Context Menu

by Mark Murphy » Sun, 13 Sep 2009 06:35:40 GMT


Here is a link to the menu documentation: 

There are many samples available. 

This example shows menu inflation, where you define the menu via an XML
file. There are many other samples showing onOptionsItemSelected() in
your SDK (platforms/android-1.5/samples wherever your SDK was installed). 

This example is really of how to use the preference system, but the
sample code shows onOptionsItemSelected() as well.

Here are two more samples: 

Beyond that, you can search Google for onOptionsItemSelected(). Or, you
can pick up a good book or three: 

You do not need a menu for that. The user can click the BACK button to
exit your activity.

Mark Murphy (a Commons Guy)  | 

Android Training in Germany, 18-22 January 2010: 


Sponsored Links

Context Menu

by Neilz » Wed, 14 Oct 2009 18:45:03 GMT

 Hi. I have a context menu, which appears when you press and hold over
a list item for around two seconds.

Is there a way to adjust the sensitivity of this? I'd like it to
appear more quickly, if that's possible?


Context Menu

by Neilz » Fri, 23 Oct 2009 17:27:27 GMT

 The Context Menu in my app (a ListActivity) is getting very annoying.
On new phone you have to select and hold the list item for so long
before the menu pops up, that it's really not very user friendly.

I want my context menu to pop up immediately when the list item is
selected. I can't find a way of triggering this. There is a method
onListItemClick() which tells me when an item has been clicked, but I
still can't use that info to trigger the context menu in any way.

What are my options here? Surely there must be some way of achieving


Context Menu

by skink » Fri, 23 Oct 2009 17:48:14 GMT


if you want your context menu to popup on single item selection then
how would you scroll very long list?


Context Menu

by Neilz » Fri, 23 Oct 2009 18:05:57 GMT

 Hmmm, good point :-)

The list I'm playing with isn't very long yet, so I hadn't noticed it.

The point is, I just changed phone from HTC Magic to HTC Hero, and the
hold duration to activate the menu is painfully long. It's not user
friendly - in fact I don't think a random user using this app would
even know that holding an item was an option! I want to be able to set
the duration of the hold required.


Context Menu

by Neilz » Sat, 24 Oct 2009 16:37:23 GMT

 > if you want your context menu to popup on single item selection then
how would you scroll very long list?

Having thought about it, I Don't agree with this... It's perfectly
usual for android to behave in this way. Think about when you are
scrolling through the apps how easy it is to open one of them by
mistake. You just have to get used to the touch sensitivity of the
screen and get better at scrolling, or selecting.

So, back to my original problem. If you can't adjust the sensitivity
required (I don't believe you can't!) to activate a ContextMenu, what
other options are there to pop up a menu?

Other Threads

1. Change color of listview in custom dialog


I created a custom dialog with a ListView to be able to use fastScroll and I 
want it to look like the dialog created with AlertDialog.Builder.
I've tried to put ListView style to Widget.ListView.White, Theme.Light but 
none works and the listview is always displayed in black.

  <ListView android:id="@+id/big_list_dialog_list"

A lot of thanks in advance,


2. How to autorun a script on startup(exec command not implemented in init.rc?)

Hi all:
    How to autorun a script to config network on startup.  I try to
use exec command in the init.rc, but it's not implemented yet?
The "do_exec" function in "builtins.c", it simply returns -1 without
doing anything.

Android version 2.2 (Froyo).
Kernel 2.6.32

Bian Jiang


3. froyo build error

4. Adding overlay items between two overlay items

5. Review Acer Iconia Tab

6. horizontal view increasing the size of a text box

7. request max heapsize?