Context Menu pops-up twice

by Bender » Fri, 02 Jul 2010 13:46:54 GMT

Sponsored Links

I'm trying to make a context menu for a little notes application, and
it has some weird behaviour. My notes are categorized in.. well
categories. I'm using a ExpandableListView to show the categories
(groups) and notes (children). I have registered for context menu, and
what happens is the following:

 * When I click and hold a category, my context menu pops up which has
one option "delete".
 * When I click delete, the category gets deleted and the context menu
disappears, but then a new context menu pops up which has also
"delete" in it, but it isnt clickable. The only way to close it is to
use the "back" button.

I don't get why that second context menu pops up and how I can get rid
of it, I hope somebody here can help me.

Here is my code, if additional code pieces please tell me. :)

        public void onCreateContextMenu(ContextMenu menu, View v,
                        ContextMenuInfo menuInfo) {
                super.onCreateContextMenu(menu, v, menuInfo);

                ExpandableListView.ExpandableListContextMenuInfo info =

                int type =

                // Context menu for categories
                if(type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
                        menu.addSubMenu(0, CONTEXT_DELETE_CAT, 0, 

                // Context menu for notes
                } else if(type == 
                        menu.addSubMenu(0, CONTEXT_DELETE_NOTE, 0, 

        public boolean onContextItemSelected(MenuItem item) {

                ExpandableListContextMenuInfo info =
                        (ExpandableListContextMenuInfo) item.getMenuInfo();

                switch(item.getItemId()) {
                case CONTEXT_DELETE_CAT:
                        long categoryId =;
                        return true;
                case CONTEXT_DELETE_NOTE:
                        long noteId =;
                        return true;
                        return super.onContextItemSelected(item);


Context Menu pops-up twice

by Justin Anderson » Fri, 02 Jul 2010 14:25:55 GMT

 What version of Android are you developing for?  Where are you setting the
context menu listener?  Do you by chance do that more than once?

There are only 10 types of people in the world...
Those who know binary and those who don't.


Sponsored Links

Context Menu pops-up twice

by Bender » Sat, 03 Jul 2010 02:05:51 GMT

 Thanks for your reply :)

I'm developing for google api 1.5 and I'm setting the context menu
once in the "onCreate()" method by my activity with:


I can't see any other place where I'm registring any context menu.


Context Menu pops-up twice

by Bender » Sat, 03 Jul 2010 16:56:29 GMT

 Maybe I should add the following: The second context menu which pops-
up doesn't contain the items from the first context menu. For example:
my context menu contains "delete" and "edit", when I push and hold one
category, the first context menu pops up with "delete" and "edit",
when I choose "delete" that context menu closes, the category gets
deleted and a new menu pops up where is only written "category" but no
options to choose from.


Context Menu pops-up twice

by Justin Anderson » Sat, 03 Jul 2010 23:09:33 GMT

 I did a quick comparison between your code and mine and found a few
differences between my code and yours...

Try removing this line of code:

And replace it with this:

In theory you shouldn't have to have the above line because
ExpandableListActivity should be doing that for you since it implements
View.OnCreateContextMenuListener, but it seems there is a bug (at least in
the 1.6 SDK) and this doesn't happen by default.

Also, place "@Override" in front of your onCreateContextMenu() and
onContextItemSelected() methods to ensure that you are overriding the
default behavior.

Hope that helps,

There are only 10 types of people in the world...
Those who know binary and those who don't.


Context Menu pops-up twice

by Bender » Thu, 08 Jul 2010 02:27:14 GMT

 I had some problems posting a response here so Justin Anderson wrote
me the solution via mail. Since that may be interesting for somebody
else I want to write it down here. I was using addSubMenu() to add
fields to the context menu which was wrong, I should have been using
add() to do this. So using add() instead of addSubMenu()
solved the problem.

Thank you so much for your help! :)

> >

Other Threads

1. Zoom out on the emulator

Hi all,
When I run the emulator with an AVD set to WVGA854, it is far too tall
and gets completely cut off my MacBook laptop screen.

Is there a way to zoom out via the emulator?  E.g. pass a scale value
on startup?  I know the same thing is possible with BlackBerry, and
thought it might exist with Android.  I browsed quickly through the
options, but could find nothing.



2. activity is destroyed when press home key

My manifest:
       <activity android:label="@string/app_name"
android:name="MainUI" android:screenOrientation="landscape"
                <action android:name="android.intent.action.MAIN" />
android:name="android.intent.category.LAUNCHER" />
       <activity android:label="@string/settings_label"
android:name=".view.Settings"  android:configChanges="orientation|

   I press program's icon to start my program,and then open the
Settings activity through startActivityForResult(intent, SETTINGS).
Now i press the  home key  and start my program through program's
icon, at this time the Settings actitity will run OnDestroy() and be
destroyed. I can't understand why Settings activity is be destroyed
automatically? How can I make Settings activity still focus when users
come back.

Thank all.


3. onFling() event not relayed to my custom View

4. How do you create a soft Home, Back, and Menu button?

5. KML Support in Maps Application

6. How do you create a soft Home, Back, and Menu button?

7. is Buggy !!!