I'm trying to pass variables from my main activity to a fragment. This is how i'm attempting to do it:
This is in my Activity:
Bundle args = new Bundle ();
args.PutString ("header", header);
args.PutString ("content", content);
args.PutString ("footer", header);
args.PutString ("imageLocation", imageLocation);
exhibitMainFragment.Arguments = args;
FragmentManager.BeginTransaction ()
.Replace (Resource.Id.main_view, exhibitMainFragment)
.AddToBackStack (null)
.Commit ();
This is in my Fragment:
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Android.OS.Bundle savedInstanceState)
{
var ignored = base.OnCreateView(inflater, container, savedInstanceState);
var view = inflater.Inflate(Resource.Layout.MuseumInformation, null);
content = this.Activity.Intent.GetStringExtra ("content");
header = this.Activity.Intent.GetStringExtra ("header");
footer = this.Activity.Intent.GetStringExtra ("footer");
imageFilePath = this.Activity.Intent.GetStringExtra ("imageLocation");
But none of the variables are being passed (they are all empty in the fragment). I'm clearly making a fundamental error here. Can somebody tell me what it is please. Or show me a better way to pass the data across.
Thanks.