In public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo} event ,
I think I can know which control launch onCreateContextMenu event by the arg View v using the following, right?
ImageView imageview=(ImageView)v
But In public boolean onContextItemSelected(MenuItem item), I can't find the same arg, how can I do? Thanks!
You can use the ContextMenu.ContextMenuInfo
like this:
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
int index = info.position;
}
You can also get the exact View for which the menu is being displayed:
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
int index = info.position;
View view = info.targetView;
}
Look to these questions:
Android: How to find the position clicked from the context menu
Identifying the view selected in a ContextMenu (Android)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With