getSupportFragmentManager

getSupportFragmentManager

名称“getSupportFragmentManager”在当前上下文中不存在

我的代码:

using Android.Views;
using Android.OS;
using Android.Support.V4.App;
using com.refractored;
using Android.Support.V4.View;

namespace XamarinStore
{
    public class HomeFragment : Android.App.Fragment
    {
        BadgeDrawable basketBadge;
        int badgeCount;

        public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            RetainInstance = true;
            SetHasOptionsMenu(true);



            // Create your fragment here
        }

        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var HomePage = inflater.Inflate(Resource.Layout.HomeLayout, container, false);

            var pager = HomePage.FindViewById<ViewPager>(Resource.Id.pager);
            pager.Adapter = new MyPagerAdapter(SupportFragmentManager);


            var tabs = HomePage.FindViewById<PagerSlidingTabStrip>(Resource.Id.tabs);
            tabs.SetViewPager(pager);

            return HomePage;
        }
    }

    public class MyPagerAdapter : FragmentPagerAdapter{
        private  string[] Titles = {"Categories", "Home", "Top Paid", "Top Free", "Top Grossing", "Top New Paid",
            "Top New Free", "Trending"};

        public MyPagerAdapter(Android.Support.V4.App.FragmentManager fm) : base(fm)
        {
        }

        public override Java.Lang.ICharSequence GetPageTitleFormatted (int position)
        {
            return new Java.Lang.String (Titles [position]);
        }
        #region implemented abstract members of PagerAdapter
        public override int Count {
            get {
                return Titles.Length;
            }
        }
        #endregion
        #region implemented abstract members of FragmentPagerAdapter
        public override Android.Support.V4.App.Fragment GetItem (int position)
        {
            return SuperAwesomeCardFragment.NewInstance (position);
        }
        #endregion
    }
}

如何获取对 fragment 中的getSupportFragmentManager的访问。

我正在使用xamarin跨平台开发工具..借助此源文件https://xamarin.com/c-sharp-shirt中的示例项目

在演示项目中,如果 BackStackEntryCount count等于零,则会将屏幕切换到另一个 fragment 。 “..在使用该组件时,它将停止并显示此错误。
在当前上下文中不存在名称“getSupportFragmentManager”

最佳答案

首先,我将HomeFragment继承为Android.Support.V4.App.Fragment
然后我用ChildFragmentManager而不是SupportFragmentManager

pager.Adapter = new MyPagerAdapter(ChildFragmentManager);

10-07 20:51