The name 'getSupportFragmentManager' does not exist in the current context
My Code:
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
}
}
How to get access to getSupportFragmentManager in fragment ..
I'am using xamarin cross platform development tool.. with the help of sample project from this source https://xamarin.com/c-sharp-shirt
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
http://components.xamarin.com/view/PagerSlidingTabStrip
getSupportFragmentManager () used when you are in activity and want to get a fragment but in the fragment you can access by use another method called getFragmentMangaer () works the same like getSupportFragmentManager () and you can use it like you used to: fragmentTransaction =getFragmentManager ().beginTransaction ();
The appropriate FragmentManager property to reference depends on where the callsite is in the fragment hierarchy along with which fragment manager you are trying to access. Once you have a reference to the FragmentManager, you can use it to manipulate the fragments being displayed to the user.
Fragments are also capable of hosting one or more child fragments. Inside a fragment, you can get a reference to the FragmentManager that manages the fragment's children through getChildFragmentManager () .
Note that setting the FragmentFactory in the activity overrides fragment creation throughout the activity's fragments hierarchy. In other words, the childFragmentManager of any child fragments you add uses the custom fragment factory set here unless overridden at a lower level.
First i inherit HomeFragment
to Android.Support.V4.App.Fragment
Then i used ChildFragmentManager
instead of SupportFragmentManager
pager.Adapter = new MyPagerAdapter(ChildFragmentManager);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With