0

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

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)
            {
            }

        }
    }
4

1 回答 1

2

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

public void OnTabSelected (ActionBar.Tab tab, FragmentTransaction ft) 
{
    Toast.MakeText(this, "Some text", ToastLength.Short).Show();
}
于 2013-01-07T18:46:59.753 回答