OnOptionsItemSelected is not called in fragment xamarin android

EnglbachEnglbach VNMember ✭✭

In OnCreate: SetHasOptionsMenu (true);

public override bool OnOptionsItemSelected(IMenuItem menu)
menu.SetChecked (true);
switch (menu.ItemId) {
case Resource.Id.selecta:
Toast.MakeText (Application.Context, "Top", ToastLength.Long);

            return true;
        case Resource.Id.selectb:
            Toast.MakeText (Application.Context, "New", ToastLength.Long);

            return true;
        return base.OnOptionsItemSelected (menu);

    public override void OnCreateOptionsMenu(Android.Views.IMenu menu,MenuInflater inflater)
        //MenuInflater.Inflate (Resource.Menu.Action_menu, menu);

        base.OnCreateOptionsMenu (menu,inflater);

When the item of checkbox is checked . OnOptionsItemSelected is not called.


  • You have to use SetHasOptionsMenu(true); in the OnCreateView() method of the fragment.cs code.
    Also you have to remove the OnOptionsItemSelected() from the activity class or just return false from there.
    It worked for, hope this will help you !! Happy coding !

Sign In or Register to comment.