Example #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_main);

            // Set up the action bar.
            ActionBar actionBar = SupportActionBar;

            actionBar.NavigationMode = (int)ActionBarNavigationMode.Tabs;

            // Create the adapter that will return a fragment for each of the three
            // primary sections of the activity.
            mSectionsPagerAdapter = new SectionsPagerAdapter(this, SupportFragmentManager);

            // Set up the ViewPager with the sections adapter.
            mViewPager         = FindViewById(Resource.Id.pager).JavaCast <ViewPager>();
            mViewPager.Adapter = mSectionsPagerAdapter;

            // When swiping between different sections, select the corresponding
            // tab. We can also use ActionBar.Tab#select() to do this if we have
            // a reference to the Tab.
            mViewPager.PageSelected += (sender, args) =>
            {
                actionBar.SetSelectedNavigationItem(args.Position);
            };

            // For each of the sections in the app, add a tab to the action bar.
            for (int i = 0; i < mSectionsPagerAdapter.Count; i++)
            {
                // Create a tab with text corresponding to the page title defined by
                // the adapter. Also specify this Activity object, which implements
                // the TabListener interface, as the callback (listener) for when
                // this tab is selected.
                var tab = actionBar
                          .NewTab()
                          .SetText(mSectionsPagerAdapter.GetPageTitle(i))
                          .SetTabListener(this);
                actionBar.AddTab(tab);
            }
        }