Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin.android ActionBar选项卡侦听器_Xamarin.android_Android Actionbar_Android Tabs - Fatal编程技术网

Xamarin.android ActionBar选项卡侦听器

Xamarin.android ActionBar选项卡侦听器,xamarin.android,android-actionbar,android-tabs,Xamarin.android,Android Actionbar,Android Tabs,我有一个带有ActionBar的简单布局,我想在用户选择选项卡时显示一条消息。我已经实现了ActionBar.ITabListener和OnTables,但它不起作用。代码有什么问题? 代码如下: namespace ICSTabs { [Activity (Label = "ICSTabs", MainLauncher = true)] public class Activity1 : Activity, ActionBar.ITabListener

我有一个带有ActionBar的简单布局,我想在用户选择选项卡时显示一条消息。我已经实现了ActionBar.ITabListener和OnTables,但它不起作用。代码有什么问题? 代码如下:

namespace ICSTabs

    {
        [Activity (Label = "ICSTabs", MainLauncher = true)]
        public class Activity1 : Activity, ActionBar.ITabListener
        {


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

                // Set our view from the "main" layout resource
                SetContentView (Resource.Layout.Main);

                ActionBar bar = ActionBar;

                bar.NavigationMode = ActionBarNavigationMode.Tabs;

                bar.AddTab (bar.NewTab ().SetText ("TEXT1")
                            .SetTabListener (this));
                bar.AddTab (bar.NewTab ().SetText ("TEXT2")
                            .SetTabListener (this));
                bar.AddTab (bar.NewTab ().SetText ("TEXT3")
                            .SetTabListener (this));


            }

            public void OnTabSelected (ActionBar.Tab tab, FragmentTransaction ft) 
            {
                Toast.MakeText(this, "Some text", ToastLength.Short);
            }

            public void OnTabUnselected (ActionBar.Tab tab, FragmentTransaction ft)
            {
            }

            public void OnTabReselected (ActionBar.Tab tab, FragmentTransaction ft)
            {
            }

        }
    }

构造
Toast
对象后,需要调用
show()
方法来实际显示Toast。这是代码

public void OnTabSelected (ActionBar.Tab tab, FragmentTransaction ft) 
{
    Toast.MakeText(this, "Some text", ToastLength.Short).Show();
}

请告诉我!目前,您正在向我们展示这是如何解决问题的。谢谢您的关注。