On Mar 14, 11:29 pm, Puneet Agarwal <[email protected]>
wrote:
> Hey android developers,
>
> I am facing problem to get the group id of ContextMenu. I can't find
> any function which can fetch the group id of ContextMenu.
> In my application i want that if i click on any of my ListView items,
> it will display a different context menu on different items of the
> list.
> Can you please help me out. If you give example code, then it will be
> appreciated.
>
> Thanks in advance

I'll try to help
1. declare a variable for the visibility of the group
int visibleGroup;

2. in the method onCreateContextMenu add a if condition / case, like
this
public void onCreateContextMenu(ContextMenu menu, View v,
                                        ContextMenuInfo menuInfo) {
          super.onCreateContextMenu(menu, v, menuInfo);
          MenuInflater inflater = getMenuInflater();
          inflater.inflate(R.menu.contmenu, menu);
         // themenu = menu;
          if (visibleGroup == 1){
                  menu.setGroupVisible(R.id.group1, true);
                  menu.setGroupVisible(R.id.group2, false);
          }else if (visibleGroup == 2){
                  menu.setGroupVisible(R.id.group1, false);
                  menu.setGroupVisible(R.id.group2, true);
          }

        }

3. in method onListItemClick, set the visibleGroup variable according
the listview item,
protected void onListItemClick(ListView l, View v, int position, long
id) {
            super.onListItemClick(l, v, position, id);
            switch (position){
            case 0:
                visibleGroup = 1;
                l.showContextMenu();
        break;
            case 1:
                visibleGroup = 2;
                l.showContextMenu();

                break;
            }

        }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to