2

I am sorry for the probably really stupid question but I am struggling with this for few hours already and I can't get it. I am a beginner in C# and I am using Xamarin Studio. I have added a Popup menu to my application but I don't know how to refer to the items in the menu (the buttons) in order to handle onClick events. Here is my code for the popup_menu:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/item1"
          android:title="Animals Delivery"
          android:onClick="AnimalsDel" />    
    <item android:id="@+id/item2"
          android:title="Food Delivery"
          android:onClick="FoodDel" />  
</menu>

The code for the menu in the Activity class is:

inputType.Click += (s, arg) => {              
            PopupMenu menu = new PopupMenu (this, inputType);
            menu.Inflate (Resource.Menu.popup_menu);

                menu.MenuItemClick += (s1, arg1) => {
                Console.WriteLine ("{0} selected", arg1.Item.TitleFormatted);
            };

            menu.DismissEvent += (s2, arg2) => {
                Console.WriteLine ("menu dismissed"); 
            };
            menu.Show ();
        };

My problem is when I am implementing the onClick methods. I know that I should give MenuItem item as parameter but in Xamarin there is no such constant .. So this is what I have till now:

public void AnimalsDel (IMenuItem item1)
    {
        inputType.Text = "Animals Delivery";
    }
    public void FoodDel (IMenuItem item2)
    {
        inputType.Text = "Food Delivery";
    }

There is an EditText in my app and I want to change the text when one of the two items from the Popup menu has been clicked. But implemented like this the app is throwing the following exception: "Couldn't resolve menu item onClick handler AnimalsDel in class deliverynote.AddActivity"

Stefan Stefanov
  • 789
  • 6
  • 23
  • Have a look at a few examples of using android action bar – InitLipton Jul 16 '14 at 09:52
  • I have had a look at a lot of examples already but they are not for Xamarin and the parameter for the onClick methods is MenuItem item, but in Xamarin there is not such constant .. that's my problem – Stefan Stefanov Jul 16 '14 at 11:18
  • Or if its something like this your looking for regarding popupmenus http://stackoverflow.com/questions/21329132/android-custom-dropdown-popup-menu – InitLipton Jul 16 '14 at 11:46
  • But in the example you sent me the onMenuItemClick method is also with parameter ManuItem item .. that's my problem, I got the rest. – Stefan Stefanov Jul 16 '14 at 11:57

0 Answers0