如何仅在xamarin.forms中使用微调器项目选择来打开另一个活动?

问题描述 投票:0回答:1

我已经尝试过了,看起来大多数搜索结果都引用了Android Studio。我正在使用Visual Studio,Xamarin形式。

protected override void OnCreate (Bundle bundle)
{
    base.OnCreate (bundle);

    SetContentView (Resource.Layout.Main);

    Spinner spinner = FindViewById<Spinner> (Resource.Id.spinner);

    spinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs> (spinner_ItemSelected);
    var adapter = ArrayAdapter.CreateFromResource (
            this, Resource.Array.my_array, Android.Resource.Layout.SimpleSpinnerItem);

    adapter.SetDropDownViewResource (Android.Resource.Layout.SimpleSpinnerDropDownItem);
    spinner.Adapter = adapter;
}

微调器完美加载,但所选项目方法在加载时打开了活动。

private void spinner_ItemSelected (object sender, AdapterView.ItemSelectedEventArgs e)
{
 SetContentView (Resource.Layout.page1);
}

如何最好地将活动加载到特定的项目选择上。 注意:这些项目在Strings.xml中引用。]。

我已经尝试过了,看起来大多数搜索结果都引用了Android Studio。我正在使用Visual Studio,Xamarin形式。受保护的重写void OnCreate(捆绑包){base.OnCreate(...

xamarin android-activity xamarin.forms spinner menuitem
1个回答
1
投票

因为Spinner初始化时默认选择第一项,它将触发spinner_ItemSelected

© www.soinside.com 2019 - 2024. All rights reserved.