2013-01-07 72 views
0

我有一個簡單的佈局與ActionBar,我想顯示一條消息,當用戶選擇一個選項卡。我已經實現了ActionBar.ITabListener和OnTabSelected,但它不起作用。代碼有什麼問題? 下面的代碼:ActionBar標籤監聽器

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

     } 
    } 

回答

2

構建Toast對象後,需要調用show()方法實際顯示的吐司。這是代碼。

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

顯示和告訴,請!目前,您只是向我們展示了這是如何解決問題的。 –

+1

謝謝。我認爲代碼是不言自明的。 –

+0

非常感謝您的關注。 –