以下方法或属性之间的调用不明确:`Android.App.AlertDialog.Builder.SetPositiveButton

luk*_*kso 3 c# android android-alertdialog xamarin

我正在尝试使用C#在Android应用程序上创建警报对话框.不幸的是我收到此错误:

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)
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

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

我究竟做错了什么?

sim*_*im1 6

你的调用.setPositiveButton("OK", null)是不明确的,因为该方法有2个重载,你的第二个参数null可以解释为:

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

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

.setPositiveButton("OK", (Android.Content.IDialogInterfaceOnClickListener)null)
Run Code Online (Sandbox Code Playgroud)