getSupportFragmentManager

getSupportFragmentManager

本文介绍了如何获取对片段中的getSupportFragmentManager或SupportFragmentManager的访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

The name 'getSupportFragmentManager' does not exist in the current context

我的代码:

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
    }
}

如何在片段中访问getSupportFragmentManager.

How to get access to getSupportFragmentManager in fragment ..

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

I'am using xamarin cross platform development tool.. with the help of sample project from this source https://xamarin.com/c-sharp-shirt

在演示项目中,如果 BackStackEntryCount count等于零,则会将屏幕切换到另一个片段..所以我用新的家庭片段替换了代码,因此我决定在该片段中添加选项卡..所以我尝试使用该组件材料寻呼机滑动标签条" ..在使用该组件时会停止,并显示此错误.名称"getSupportFragmentManager"在当前上下文中不存在

In the demo project if BackStackEntryCount count equals to zero it switch screen to another fragment.. so i replaced code with new homefragment i decided to add tabs in the that.. so i tried to use this component "Material Pager Sliding Tab Strip" .. while using that component it stops with this error.the name 'getSupportFragmentManager' does not exist in the current context

推荐答案

首先,我将 HomeFragment 继承到 Android.Support.V4.App.Fragment

然后我使用了 ChildFragmentManager 而不是 SupportFragmentManager

pager.Adapter = new MyPagerAdapter(ChildFragmentManager);

这篇关于如何获取对片段中的getSupportFragmentManager或SupportFragmentManager的访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-22 08:08