我是Android开发人员的新手,C#并没有组件的经验。我正在使用Xamarin android并且目前遇到工具栏菜单项的问题。我想要的是当按下其中一个项目时,它会调用另一个功能。目前我不知道如何获得该项目的ID。以下是我的代码。
public override bool OnOptionsItemSelected(IMenuItem item)
{
Type thing = item.GetType();
String id = FindViewById <thing> (V002.Resource.Id.menu_edit);
if (id == "menu_edit") {
}
Toast.MakeText(this, "Action selected: " + item.TitleFormatted,
ToastLength.Short).Show();
return base.OnOptionsItemSelected(item);
}
}
答案 0 :(得分:0)
public override bool OnOptionsItemSelected(IMenuItem item)
{
Type thing = item.GetType();
String id = item.ItemId;
switch(id){
case Resource.Id.menu_edit:
// - Do whatever you want to do here
return true;
}
Toast.MakeText(this, "Action selected: " + item.TitleFormatted,
ToastLength.Short).Show();
default:
return base.OnOptionsItemSelected(item);
}
}