如何获取布局气筒给定一个上下文?气筒、上下文、布局

2023-09-04 23:45:44 作者:卖血来上网

我写一个自定义实现一个ListAdapter的。

I am writing a custom implementation of a ListAdapter.

在它的构造,我正在一个背景下,资源ID(即R.id.xxx重新presenting布局文件),以及列表和地图(这些包含的数据)。

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).

现在的问题是,我需要一个LayoutInflater拿到这是分离的布局XML文件中的视图对象。

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

我怎么能弄个只给出背景下LayoutInflater的?

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

现在,为什么我认为这是可能的,是,这是颇为相似的是什么传递给ArrayAdapter(背景下,资源,textViewResourceId,数据数组)的构造函数,我想一个ArrayAdapter也有使使用只给出一个上下文一个LayoutInflater的。

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.

但怎样才能做到呢?

推荐答案

您可以使用静态 from()从 LayoutInflater 类方式:

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

 LayoutInflater li = LayoutInflater.from(context);
 
精彩推荐
图片推荐