views:

1310

answers:

1

Hi,

i am writing a custom implementation of a ListAdapter.

In its constructor, i'm taking in a Context, a resource ID (i.e. R.id.xxx representing the layout file), and a list and a map (these contain the data).

Now, the problem is that i will need a LayoutInflater to get the View object which is in the separate layout XML file.

How can i get hold of the LayoutInflater given only the Context?

Now, why i think this is possible, is that this is quite similar to what is being passed in to the constructor of an ArrayAdapter (context, resource, textViewResourceId, data array), and i figure the ArrayAdapter also has to make use of a LayoutInflater given only a Context.

But how can it be done?

+7  A: 

You can use the static from() method from the LayoutInflater class:

 LayoutInflater li = LayoutInflater.from(context);
Dave Webb
Thanks! i was trying to find Context.getSomething().getAnotherThing().getLayoutInflater() !
Edwin Lee