Reputation: 1271
I am using Xamarin
and have a question about getting a View
from a Layout
.
If I have a Layout
called custom_info_window
, how can I get a View
from this?
I have tried this code:
View v = Inflate(Resource.Layout.custom_info_window, null);
This is the error I am getting:
Error CS0103: The name 'Inflate' does not exist in the current context
Can I please have some help with this?
Thanks in advance
EDIT
Here is my code for the inflater:
LayoutInflater inflater =(LayoutInflater)Context.GetSystemService(Context.LayoutInflaterService);
This is the error I am getting:
Error CS0120: An object reference is required for the non-static field, method, or property 'Android.Content.Context.GetSystemService(string)'
Upvotes: 1
Views: 2792
Reputation: 5234
You will need to use a Context object to get the service. If nothing else works, use static property Application.Context:
var inflater = Application.Context.GetSystemService(Context.LayoutInflaterService) as LayoutInflater;
var view = inflater.Inflate(...
Upvotes: 0
Reputation: 11323
it should be also possible to get a LayoutInflater from the context, something like:
LayoutInflater.from(getApplicationContext()).inflate(Resource.Layout.custom_info_window, null);
Upvotes: 1
Reputation: 18933
You should use this one..
LayoutInflater inflater = (LayoutInflater)this.GetSystemService(Context.LayoutInflaterService);
var layout = inflater.Inflate(Resource.Layout.custom_info_window, layoutImages) as LinearLayout;
Upvotes: 1
Reputation: 9700
LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = mInflater.inflate((Resource.Layout.custom_info_window, null);
Upvotes: 1