Reputation: 291
I have a simple layout with an ActionBar and I would like to show a message when a user selects a tab. I've implemented ActionBar.ITabListener and OnTabSelected but it doesn't work. What is wrong with the code? Here's the code:
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)
{
}
}
}
Upvotes: 0
Views: 523
Reputation: 5549
After constructing a Toast
object, you need to call the show()
method to actually display the Toast. Here is the code.
public void OnTabSelected (ActionBar.Tab tab, FragmentTransaction ft)
{
Toast.MakeText(this, "Some text", ToastLength.Short).Show();
}
Upvotes: 2