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"