Grid view worked in activity, not working in fragment. How do I fix this?

I have a grid view that's working perfectly when I use it in an activity, but when I try to use it in a fragment I get a System.NullReferenceException at the row where I call the adapter. I've tried adapting the code for use in a fragment, but I guess I'm doing something wrong. What am I doing wrong and what can I do about it?

Here's the code for the fragment:

public class SituationFragment : Fragment
{
    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        var view = inflater.Inflate(Resource.Layout.situationButtonGrid, container, false);

        List<string> situationTitles = new List<string> {"Name 1","Name 2","Name 3"};
        var gridViewSituation = Activity.FindViewById<GridView> (Resource.Id.situationButtonGridView);
        gridViewSituation.Adapter = new SituationButtonAdapter (this.Activity, situationTitles);
        return view;
    }
}
Sign In or Register to comment.