Android: how to create ContextMenu for custom view

I would like to show ContextMenu for a custom view that is not part of the AdapterView.

I called

myActivity.registerForContextMenu(myView);

and ContextMenu is already appearing.

But I don't know how to access myView data in

@Override
onContextItemSelected(MenuItem item) //...

I thought I could create a custom menuInfo in

@Override
onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) //...

This is from the documents: "menuInfo - additional information about the item for which the context menu should be displayed. This information will depend on class v.

Can anyone give me a hint?

+3
source share
1 answer

getContextMenuInfo() , ContextMenuInfo ( , !) , .

onContextItemSelected(MenuItem item), item.getMenuInfo() .

+5

Source: https://habr.com/ru/post/1771310/


All Articles