2013-03-06 61 views
3

现在我试图用C#在Android应用程序上创建一个Alert Dialog。不幸的是我得到这个错误:这个调用在下面的方法或属性之间是不明确的:`Android.App.AlertDialog.Builder.SetPositiveButton

The call is ambiguous between the following methods or properties: `Android.App.AlertDialog.Builder.SetPositiveButton(string, System.EventHandler<Android.Content.DialogClickEventArgs>)' and `Android.App.AlertDialog.Builder.SetPositiveButton(string, Android.Content.IDialogInterfaceOnClickListener)' (CS0121) (App) 

这是我的代码:

var alert = new AlertDialog.Builder(this).SetTitle("Title").SetMessage("Message").setPositiveButton("OK", null); 
alert.Show(); 
return true; 

我在做什么错?

+2

将“null”投射到Android.Content.DialogClickEventArgs。 – Luksprog 2013-03-06 09:49:16

回答

5

您到.setPositiveButton("OK", null)电话是模糊的,因为该方法有2个过载和你的第二个参数为空可以解释为:

  • System.EventHandler<Android.Content.DialogClickEventArgs>
  • 或作为Android.Content.IDialogInterfaceOnClickListener

,如果你想调用第二次过载,试试这个:

.setPositiveButton("OK", (Android.Content.IDialogInterfaceOnClickListener)null) 
相关问题