如何在Xamarin上使用SetOnMenuItemClickListener?

时间:2016-05-07 19:00:36

标签: c# android visual-studio xamarin menuitem

我找到this question,然后我意识到Java代码不能用于C#,我不知道如何实现这个代码:

amvMenu.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() {
  @Override
  public boolean onMenuItemClick(MenuItem menuItem) {
    return onOptionsItemSelected(menuItem);
  }
});

导致错误:

Cannot create an instance of the abstract class or interface 'ActionMenuView.IOnMenuItemClickListener

到目前为止我的代码:

tbchild.SetOnMenuItemClickListener(new ActionMenuView.IOnMenuItemClickListener() {
  public bool onMenuItemClick(IMenuItem menuItem)
    {
        return OnOptionsItemSelected(menuItem);
    }
});

由于

1 个答案:

答案 0 :(得分:2)

ActionMenuView有一个MenuItemClick事件,您可以使用它来代替侦听器。

amv.MenuItemClick+= delegate(object sender, ActionMenuView.MenuItemClickEventArgs e)
{
    // your code for the click
};