如何获取工具栏菜单项的 ID?
How to get the id of a toolbar menu item?
我是 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);
}
}
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);
}
}
我是 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);
}
}
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);
}
}