Cheesebaron.HorizontalPager.Activity1.OnCreate C# (CSharp) Method

OnCreate() protected method

protected OnCreate ( Bundle bundle ) : void
bundle Bundle
return void
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            var display = WindowManager.DefaultDisplay;
            var horiPager = new HorizontalPager(this.ApplicationContext, display);
            horiPager.ScreenChanged += new ScreenChangedEventHandler(horiPager_ScreenChanged);

            //You can also use:
            /*horiPager.ScreenChanged += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("Switched to screen: " + ((HorizontalPager)sender).CurrentScreen);
            };*/

            var backgroundColors = new Color[] { Color.Red, Color.Blue, Color.Cyan, Color.Green, Color.Yellow };

            for (int i = 0; i < 5; i++)
            {
                var textView = new TextView(this.ApplicationContext);
                textView.Text = (i + 1).ToString();
                textView.TextSize = 100;
                textView.SetTextColor(Color.Black);
                textView.Gravity = GravityFlags.Center;
                textView.SetBackgroundColor(backgroundColors[i]);
                horiPager.AddView(textView);
            }

            SetContentView(horiPager);
        }