我需要將選定的項目從我的微調框中移除,但出現上述錯誤,我不知道爲什麼。錯誤:'Spinner'不包含getSelectedItem的定義'...'
因此,我期望在不調用微調控件的事件處理程序的情況下獲取微調控件選定的項目,如果可能的話,因爲我需要在按鈕點擊時使用它。
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
Button bt_ok = FindViewById<Button>(Resource.Id.bt_ok);
Spinner spinner = (Spinner)FindViewById<Spinner>(Resource.Id.dd_spinner);
//
//getSelectedItem does not contain a definition!!!
//
String spinner_text = spinner.getSelectedItem().toString();
//
//Do I need this?
//
spinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);
var adapter = ArrayAdapter.CreateFromResource(
this, Resource.Array.planet_array, global::Android.Resource.Layout.SimpleSpinnerItem);
adapter.SetDropDownViewResource(global::Android.Resource.Layout.SimpleSpinnerDropDownItem);
spinner.Adapter = adapter;
bt_ok.Click += delegate
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.SetTitle("Confirm");
//
//I need the value here!!!
//
builder.SetMessage(new Confirm().Choice(spinner_text));
builder.SetCancelable(true);
builder.SetPositiveButton("Yes", delegate { });
builder.Show();
};
}
您應該考慮與[Xamarin文檔】熟悉自己(https://developer.xamarin.com //)。掃描API文檔可以幫助您找出Android Java API和Xamarin C#API之間的這些差異。 –