2013-03-06 73 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) 
相關問題