[mono-android] TabView not responding as it should

Paul Johnson paul at all-the-johnsons.co.uk
Fri Feb 24 00:59:15 UTC 2012


Hi,

I have a tabview app in development which on the face of it looks to 
work, but it isn't.

The event for changing the tab works, but the new view isn't showing. If 
I click on another tab, that fires. If I go back to the first tab, 
nothing fires. The code below explains it...

[Activity]
     public class HomeTab : Activity
     {
         protected override void OnCreate(Bundle savedInstanceState)
         {
             base.OnCreate(savedInstanceState);
             Console.WriteLine("in home");
             SetContentView(Resource.Layout.main_original);
         }
     }
     [Activity]
     public class CalendarTab : Activity
     {
         protected override void OnCreate(Bundle savedInstanceState)
         {
             base.OnCreate(savedInstanceState);
             Console.WriteLine("in calendar");
             SetContentView(Resource.Layout.five_buttons);
         }
     }
//
    [Activity(Label = "OQHRA", MainLauncher = true, 
Theme="@android:style/Theme.NoTitleBar", Icon = "@drawable/icon")]
     public class Activity1 : TabActivity
     {
         public int screenNo = -1; // quick hack
         protected override void OnCreate(Bundle bundle)
         {
             base.OnCreate(bundle);
             SetContentView(Resource.Layout.main_original);
             ListView listView = 
FindViewById<ListView>(Resource.Id.listView);
             string[] falco = 
Resources.GetStringArray(Resource.Array.frontpage);
             listView.Adapter = new ArrayAdapter<string>(this, 
Resource.Layout.listview_layout, falco);
             listView.ItemClick +=new 
EventHandler<ItemEventArgs>(listView_ItemClick);
             ImageView image = FindViewById<ImageView>(Resource.Id.imgBack);
             image.Focusable = true;
             image.Clickable = true;
             image.Click += image_Click;
             TabHost.TabSpec spec;
             Intent intent;
             intent = new Intent(this, typeof(HomeTab));
             intent.AddFlags(ActivityFlags.NewTask);
             spec = TabHost.NewTabSpec("tabHome");
             spec.SetIndicator("Home", 
Resources.GetDrawable(Resource.Drawable.ic_tabs_home));
             spec.SetContent(intent);
             TabHost.AddTab(spec);
             intent = new Intent(this, typeof(CalendarTab));
             intent.AddFlags(ActivityFlags.NewTask);
             spec = TabHost.NewTabSpec("tabCalendar");
             spec.SetIndicator("Calendar", 
Resources.GetDrawable(Resource.Drawable.ic_tabs_cal));
             spec.SetContent(intent);
             TabHost.AddTab(spec);
             intent = new Intent(this, typeof(RaceTab));
             intent.AddFlags(ActivityFlags.NewTask);
             spec = TabHost.NewTabSpec("tabRaceInfo");
             spec.SetIndicator("Race Info", 
Resources.GetDrawable(Resource.Drawable.ic_tabs_race));
             spec.SetContent(intent);
             TabHost.AddTab(spec);
             intent = new Intent(this, typeof(NewsTab));
             intent.AddFlags(ActivityFlags.NewTask);
             spec = TabHost.NewTabSpec("tabNews");
             spec.SetIndicator("News", 
Resources.GetDrawable(Resource.Drawable.ic_tabs_news));
             spec.SetContent(intent);
             TabHost.AddTab(spec);
             TabHost.CurrentTab = 0;
         }

When you click a tab, it puts in the console which tab has been pressed 
- if I click on the first tab, home is printed, second gives calendar 
and so on. Go to any tab and back to home, nothing is printed.

Any ideas why the contentview isn't showing or why the event only fires 
once?

Thanks

Paul




More information about the Monodroid mailing list