質問

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)'
役に立ちましたか?

解決

You should use this one..

 LayoutInflater inflater = (LayoutInflater)this.GetSystemService(Context.LayoutInflaterService);
 var layout = inflater.Inflate(Resource.Layout.custom_info_window, layoutImages) as LinearLayout;

他のヒント

LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = mInflater.inflate((Resource.Layout.custom_info_window, null);

it should be also possible to get a LayoutInflater from the context, something like:

 LayoutInflater.from(getApplicationContext()).inflate(Resource.Layout.custom_info_window, null);

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(...
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top