Goodday Am to Xamarin.Android和我一直在处理如何根据第一个选项填充第二个微调器,但我还没有成功。恩。我有一个旋转器"国家"如果用户选择"美国",那么第二个微调器应该立即填充美国的状态。我看到的例子是Java的例子。请帮帮我。谢谢 这是我试过的
spinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);
var adapter = ArrayAdapter.CreateFromResource(
view.Context, Resource.Array.planets_array, Android.Resource.Layout.SimpleSpinnerItem);
adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
spinner.Adapter = adapter;
if (spinner.SelectedItemPosition == 0)
{
var adapter1 = ArrayAdapter.CreateFromResource(
view.Context, Resource.Array.plane_array, Android.Resource.Layout.SimpleSpinnerItem);
adapter1.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
spinner.Adapter = adapter1;
}
return view;
}
private void spinner_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
{
}
private void spinner1_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
{
}
但第二个旋转器不会填充。
答案 0 :(得分:0)
您需要做的事情涉及以下步骤:
按如下方式添加事件和微调器对象:
Spinner _spinner1,_spinner2;
_spinner=FindViewById<Spinner>(Resource.Layout._spinner1);
_spinner.FindViewById<Spinner>(Resource.Layout._spinner2);
_spinner1.ItemSelected += ItemSelected_Spinner1;
_spinner2.ItemSelected += ItemSelected_Spinner2;
在第一个微调器的itemSelected上启用第二个:
private void ItemSelected_Spinner1(object sender, AdapterView.ItemSelectedEventArgs e)
{
_spinner2.Clickable="true";
}
还可根据需要在事件结束时更新微调器适配器内容
var adapter1 = ArrayAdapter.CreateFromResource(
view.Context, Resource.Array.plane_array, Android.Resource.Layout.SimpleSpinnerItem);
adapter1.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
_spinner2.Adapter = adapter1;