simao
simao

Reputation: 15529

Get ContextMenu associated with a ListView Item in BindView

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

Upvotes: 1

Views: 1286

Answers (1)

gngr44
gngr44

Reputation: 1368

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
}

Upvotes: 3

Related Questions