view
isn't passed to onContextItemSelected
and
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
long buttonId = info.id;
This code doesn't help because menuInfo
is null
when view is a button
. The Android doc says "menuInfo Extra information about the item for which the context menu should be shown. This information will vary depending on the class ofv
". When v
is a ListView
menuInfo
approach is fine. When it is a Button
, it doesn't work.
In onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
, the View v
is the button
that produced the context menu. Copyv
to a global View
varaiable and use that where you need to have the view of the button that produced the context menu.