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

ActionBar SupportLibrary with ViewPager

$
0
0

Hi all, I have Resouces/Layout/Main.axml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>
and: `using System;

using Android.Content; using Android.Runtime; using Android.Views; using Android.Widget; using Android.OS; using Android.Support.V7; using Android.Support.V7.App; using Android.Support.V4.App;

namespace AndroidApplication1 { [Android.App.Activity(Label = "ActionBarCompat", Icon = "@drawable/icon", Theme = "@style/Theme.AppCompat.Light", MainLauncher = true)] public class Activity1 : ActionBarActivity, ActionBar.ITabListener { ActionBar actionBar; protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); RequestWindowFeature(WindowFeatures.ActionBar); actionBar = SupportActionBar; actionBar.SetDisplayHomeAsUpEnabled(true); actionBar.NavigationMode = Android.Support.V7.App.ActionBar.NavigationModeTabs; SetContentView(Resource.Layout.Main); ActionBar.Tab tab1 = actionBar.NewTab(); tab1.SetText("tab1"); tab1.SetTabListener(this); actionBar.AddTab(tab1);

        ActionBar.Tab tab2 = actionBar.NewTab();
        tab2.SetText("tab2");
        tab2.SetTabListener(this);
        actionBar.AddTab(tab2);
    } 
public void OnTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {

}

public void OnTabSelected(ActionBar.Tab tab, FragmentTransaction ft)
{
    ft.Replace(Resource.Id.pager,new myFragmet());
}

public void OnTabUnselected(ActionBar.Tab tab, FragmentTransaction ft)
{

}

}

public class myFragmet : Fragment
{
    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        var view = new TextView(Activity);
        view.Text = "23232";
        return view;
    }
}

}`

But when I change selected tab on the screen nothing happens. Why? Thanks


Viewing all articles
Browse latest Browse all 204402

Trending Articles



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