gpt4 book ai didi

android - 如何访问 fragment 中的 getSupportFragmentManager 或 SupportFragmentManager

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:36:49 27 4
gpt4 key购买 nike

名称“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 计数等于零,它会将屏幕切换到另一个 fragment ..所以我用新的 homefragment 替换了代码我决定在其中添加选项卡..所以我尝试使用此组件“Material Pager Sliding Tab Strip”.. 在使用该组件时它会因此错误而停止。名称“getSupportFragmentManager”在当前上下文中不存在

http://components.xamarin.com/view/PagerSlidingTabStrip

最佳答案

首先我继承HomeFragmentAndroid.Support.V4.App.Fragment

然后我使用 ChildFragmentManager 而不是 SupportFragmentManager

pager.Adapter = new MyPagerAdapter(ChildFragmentManager);

关于android - 如何访问 fragment 中的 getSupportFragmentManager 或 SupportFragmentManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29531643/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com