0
votes

Now I can't seem to find any help for this on the internet so I'm doing something wrong obviously, or I'm typing the wrong thing into google. I'm using Xamarin to creating an Android app and I'm trying to use Fragments within the app.

In the fragment file I'm trying to set the LayoutInflater in the OnCreateView method. However, when I state the layout file "Resource.Layout.Profile" it's coming through as an int instead of a layout inflater? I've tried casting it as a layout inflater and it causes an exception saying it can't be cast to that.

Code:

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        return base.OnCreateView(Resource.Layout.Profile, container, savedInstanceState);
    }

Now I'm not massively experienced at Native Android development (only what I've done at University) and this is my first Xamarin Android app so I think I'm doing something wrong?

2

2 Answers

3
votes

You are passing a Ressource.Layout.Profile. That's not a Layout inflater. The layout inflater is the variable you receive under the name inflater.

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        return base.OnCreateView(inflater, container, savedInstanceState);
    }
0
votes

Turns out the error was the fact that I had it re-calling OnCreateView still whereas in the guide they changed it to inflater.Inflate.

I had this: return base.OnCreateView(Resource.Layout.Profile, container, savedInstanceState);

But needed this: return inflater.Inflate(Resource.Layout.Profile, container, false);