I'm trying to transfer to a new fragment when an item in my recycler view is clicked:
FragmentTransaction fragmentTx = ((AppCompatActivity)Activity).SupportFragmentManager.BeginTransaction();
fragmentTx.Replace(Resource.Id.container, fragment);
But the following error is raised:
System.NullReferenceException: Object reference not set to an instance of an object.
I've tried so many different things but it's not working.
I get the recycler view click from this:
private void MMainView_Click(object sender, EventArgs e)
{
int position = mRecyclerView.GetChildAdapterPosition((View)sender);
int indexPosition = (mFavourites.Count - 1) - position;
favFragment.TransitionOnCardClick(mFavourites[indexPosition].CalcName);
}
which then calls this method in the fragment that has the recycler view:
public void TransitionOnCardClick(string cardName)
{
Fragment fragment = null;
switch (cardName)
{
case "Pace":
fragment = splitFragment;
break;
case "Watts":
fragment = wattFragment;
break;
case "Weight Adjustment":
fragment = weightFragment;
break;
}
FragmentTransaction fragmentTx = ((AppCompatActivity)Activity).SupportFragmentManager.BeginTransaction();
fragmentTx.Replace(Resource.Id.container, fragment);
fragmentTx.AddToBackStack(null);
fragmentTx.Commit();
}
How do I fix this? My question is different to others as i have tried so many different ways yet i have not found a solution.