There may be no way to attach a listener to the Dialog or to the ContextMenu
itself, but it turns out that the individual MenuItem
s that the ContextMenu
contains do support a listener interface. The answer, therefore, is to modify ContextMenuGenerator
thus:
@Override
public void onCreateContextMenu (ContextMenu menu, View v, ContextMenuInfo menuInfo)
{
new MenuInflater(context).inflate (R.menu.address_set_preference_popup, menu);
for (int i = 0; i < menu.size (); i ++)
menu.getItem (i).setOnMenuItemClickListener (listener);
}
where listener
is an OnMenuItemClickListener
that I passed in to the constructor and stored in a field.