Context Menu pops-up twice

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


Sponsored Links
 Hi,

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 =
                        (ExpandableListView.ExpandableListContextMenuInfo) 
menuInfo;

                int type =
ExpandableListView.getPackedPositionType(info.packedPosition);

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

                // Context menu for notes
                } else if(type == 
ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
                        menu.addSubMenu(0, CONTEXT_DELETE_NOTE, 0, 
R.string.delete);
                }
        }

        public boolean onContextItemSelected(MenuItem item) {

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

                switch(item.getItemId()) {
                case CONTEXT_DELETE_CAT:
                        long categoryId = info.id;
                        db.categories.deleteWithNotes(categoryId);
                        mAdapter.notifyDataSetChanged();
                        fillView();
                        return true;
                case CONTEXT_DELETE_NOTE:
                        long noteId = info.id;
                        db.notes.delete(noteId);
                        fillView();
                        getExpandableListView().expandGroup(mOpenedCategory);
                        return true;
                default:
                        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:

registerForContextMenu(getExpandableListView());

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:
*registerForContextMenu(getExpandableListView());*

And replace it with this:
getExpandableListView().setOnCreateContextMenuListener(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,
Justin

----------------------------------------------------------------------
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. Fw:problem with porting media player to real hardware

Hi,

andoid settings->display->never ttimeout.

HarishKumar.V





--~--~---------~--~----~------------~-------~--~----~
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

2. How to access the page which need user name and password

hello   
      
               how to access for this formate url 
.http://myusername:mypassw...@www.mysite.com   















                                      pls help .thanks 

                        
--------------
Cloudy
2009-03-11


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

3. How to use fprintf() for stdout/stderr on Android v1.1 SDK Release 1?

4. Make a button from an image (PNG)

5. Fw:problem with porting media player to real hardware

6. detecting paused state

7. Confusing situation/crash in onPause()