Bug 6149 - OnContextItemSelected not called
Summary: OnContextItemSelected not called
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.2.x
Hardware: Macintosh Mac OS
: Normal major
Target Milestone: ---
Assignee: Marek Habersack
URL:
Depends on:
Blocks:
 
Reported: 2012-07-16 17:46 UTC by Tim Kerger
Modified: 2014-07-11 07:39 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NOT_REPRODUCIBLE

Description Tim Kerger 2012-07-16 17:46:58 UTC
I'm trying to set up a Context Menu according to Android's specs: http://developer.android.com/guide/topics/ui/menus.html#FloatingContextMenu

Everything is going well, but it seems that the most important step of all is not happening: the method OnContextItemSelected is never called. However, setup seems to be okay as I'm seeing my Context Menu. Only not responsive to selection.

Setup
1/ Calling a DialogFragment from an activity. This dialogfragment has several views, under which a listview on which I would like the Context Menu.
2/ In my fragment:
public override Android.Views.View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
listview = v.FindViewById<ListView>(Resource.Id.recordingsListView);
listview.Adapter = adapter;
listview.ItemClick += (sender, e) => {
 startPlaying(adapter[e.Position]);
};
RegisterForContextMenu(listview);
...
}

...

public override void OnCreateContextMenu (IContextMenu menu, Android.Views.View v, IContextMenuContextMenuInfo menuInfo)
{
  base.OnCreateContextMenu (menu, v, menuInfo);
  MenuInflater inflater = Activity.MenuInflater;
  inflater.Inflate (Resource.Menu.VoiceNoteContextMenu, menu);
}

public override bool OnContextItemSelected (IMenuItem item)
{
  Console.WriteLine("Selected");
  return true;
}
3/ My activity contains nothing concerning context menus. Action bar is present but hidden in this activity.
4/ Use the Support Library but not for this activity and fragment.
5/ I'm not using OnMenuItemSelected anywhere (saw that this might cause trouble)
Comment 1 Miguel de Icaza [MSFT] 2013-05-22 15:57:00 UTC
PJ, could we turn this into a self-contained test case so we can review this?
Comment 2 Marek Habersack 2014-07-11 07:39:07 UTC
I've just tested the context menu samples we have in monodroid-samples repository and they all work fine.

Without the test case I can only suppose that the original code used ActionBarSherlock which defines its own IMenuItem and, if the usings include the ActionBarSherlock namespace, the OnContextItemSelected signature will not match the one expected by Android (which needs Android.Views.IMenuItem). Perhaps using the full type name in OnContextItemSelected will make the code work?

Please attach a small test case and reopen the bug if you're still seeing the problem. Thanks!