1

When using a custom adapter, with a BindView method, is it possible to obtain the ContextMenu object associated with the view being bound?

I would like to change the items displayed in the context menu depending on the item being displayed and I can't find a way to obtain the corresponding ContextMenu.

Thanks

simao
  • 14,491
  • 9
  • 55
  • 66

1 Answers1

3

You can get the position and other details of the item from the menuInfo:

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    final AdapterContextMenuInfo adapterMenuInfo = (AdapterContextMenuInfo) menuInfo;
    int pos = adapterMenuInfo.position;
    // Do what you will
}
gngr44
  • 1,368
  • 9
  • 10
  • Actually, I was approaching this the wrong way. onCreateContextMenu is called only when the user long presses the ListView item, so I can only change the context menu there. Thanks. – simao Feb 13 '11 at 03:32
  • http://stackoverflow.com/questions/2453620/android-how-to-find-the-position-clicked-from-the-context-menu is a more in-depth look. Yours works when a context menu is created, but not when an item is selected. –  Aug 29 '12 at 17:43