Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

ViewPager example with Android 4.0

$
0
0

Hi,

I am trying to implement the ViewPager specifically swiping with tabs in 4.0 and the actionbar.

I have not been able to find any Xamarin documentation and am hopeful the community can assist me with an example.

Issues faced, I have located ViewPager in Android.Support.V4.View but it can not be added into your layout with the designer, I have not been successful adding it programaticaly either

Any help appreciated

Thanks

Here was a failed attempt

public class Activity1 : Activity, Android.Support.V4.View.ViewPager.IOnPageChangeListener
{

    public Android.Support.V4.View.ViewPager vPager;

    public void OnPageSelected(int page)
    {
        vPager.AddView(new FragmentTab1().View);
    }

    public void OnPageScrollStateChanged(int a)
    {

    }

    public void OnPageScrolled(int a, float b, int c)
    {

    }

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);

        this.ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;

        vPager = new Android.Support.V4.View.ViewPager(this);
        vPager.SetOnPageChangeListener(this);

        FrameLayout fl = FindViewById<FrameLayout>(Resource.Id.frameLayout1);
        fl.AddView(vPager);

        //TABS
        ActionBar.Tab tab1 = ActionBar.NewTab();
        tab1.SetText("Tab 1");
       tab1.TabSelected += delegate(object sender,ActionBar.TabEventArgs e)
       {
           vPager.SetCurrentItem(tab1.Position, true);
           //e.FragmentTransaction.Add(Resource.Id.frameLayout1, new FragmentTab1());
       };

        ActionBar.Tab tab2 = ActionBar.NewTab();
        tab2.SetText("Tab 2");
        tab2.TabSelected += delegate(object sender, ActionBar.TabEventArgs e)
        {
            vPager.SetCurrentItem(tab1.Position, true);
           // e.FragmentTransaction.Add(Resource.Id.frameLayout1, new FragmentTab2());
        };

        this.ActionBar.AddTab(tab1);
        this.ActionBar.AddTab(tab2);

    }




}

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>