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);
                }
        }

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to