gpt4 book ai didi

android - 当我在 fragment 中使用 tablayout 和 viewpager 时出现问题

转载 作者:行者123 更新时间:2023-11-30 01:17:47 25 4
gpt4 key购买 nike

您好,我在 fragment 中有一个 TabLayout 和 ViewPager

public class Explore : Android.Support.V4.App.Fragment, AppCompatActivity
{
private TabLayout tablayout;
private ViewPager viewPager;
private TimeBuget timeBuget;
private SpecialActivity specialActivity;
public override void OnCreate (Bundle savedInstanceState)
{
base.OnCreate (savedInstanceState);

// Create your fragment here
}

public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Use this to return your custom view for this Fragment
// return inflater.Inflate(Resource.Layout.YourFragment, container, false);

//return base.OnCreateView (inflater, container, savedInstanceState);
return inflater.Inflate(Resource.Layout.ExploreLayout,container,false);

viewPager = View.FindViewById<ViewPager> (Resource.Id.viewpagerExplore);
setupViewPager (viewPager);

tablayout = View.FindViewById<TabLayout> (Resource.Id.sliding_tabsExplore);
tablayout.SetupWithViewPager (viewPager);
}

private void InditialFragment()
{
timeBuget = new TimeBuget ();
specialActivity = new SpecialActivity ();
}
public void setupViewPager(ViewPager viewPager)
{
InditialFragment ();
ViewPagerAdapter adapter = new ViewPagerAdapter (SupportFragmentManager);
adapter.addFragment (timeBuget, "Explore");
adapter.addFragment (specialActivity, "Featured");

viewPager.Adapter=adapter;
}
}
  1. 类不能有多个基类。
  2. 如果我不使用 AppCompatActivity,那么我就不能使用 SupportFragmentManager

如何解决?

最佳答案

您必须在 Activity 中托管 fragment ,而不是同时使用两者。完成之后,您可以像这样访问 SupportFragmentManager:

ViewPagerAdapter adapter = new ViewPagerAdapter ((SpecialActivity as AppCompatActivity).SupportFragmentManager);

关于android - 当我在 fragment 中使用 tablayout 和 viewpager 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37582775/

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