嗨,我正在尝试为 Android 做 Spinner 教程。
http://docs.xamarin.com/android/tutorials/User_Interface/spinner
我收到错误:
Cannot implicitly convert type 'System.EventHandler<Android.Widget.ItemEventArgs>' to 'System.EventHandler<Android.Widget.AdapterView.ItemSelectedEventArgs>' (CS0029)
在我的 Activity1.cs 的第 26 行。我刚刚从教程中复制了代码,所以我不确定我需要将这一行更改为什么以便我可以运行它。这是我的 Activity1.cs :
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace HelloSpinner
{
[Activity (Label = "HelloSpinner", MainLauncher = true)]
public class Activity1 : Activity
{
int count = 1;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "Main" layout resource
SetContentView (Resource.Layout.Main);
Spinner spinner = FindViewById<Spinner> (Resource.Id.spinner);
spinner.ItemSelected += new EventHandler<ItemEventArgs> (spinner_ItemSelected);
var adapter = ArrayAdapter.CreateFromResource (
this, Resource.Array.planets_array, Android.Resource.Layout.SimpleSpinnerItem);
adapter.SetDropDownViewResource (Android.Resource.Layout.SimpleSpinnerDropDownItem);
spinner.Adapter = adapter;
}
private void spinner_ItemSelected (object sender, ItemEventArgs e)
{
Spinner spinner = (Spinner)sender;
string toast = string.Format ("The planet is {0}", spinner.GetItemAtPosition (e.Position));
Toast.MakeText (this, toast, ToastLength.Long).Show ();
}
}
}