如何根据上下文获取布局Inflater? - How to Get a Layout Inflater Given a Context?

10/14 15:29
阅读数 0

问题:

I am writing a custom implementation of a ListAdapter. 我正在编写ListAdapter的自定义实现。

In its constructor, I'm taking in a Context, a resource ID (ie R.id.xxx representing the layout file), and a list and a map (these contain the data). 在它的构造函数中,我接受一个Context,一个资源ID(即代表布局文件的R.id.xxx),一个列表和一个map(这些包含数据)。

Now, the problem is that i will need a LayoutInflater to get the View object which is in the separate layout XML file. 现在,问题是我需要一个LayoutInflater来获取View对象,该对象位于单独的布局XML文件中。

How can I get hold of the LayoutInflater given only the Context? 如果只给出Context,我怎样才能获得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. 现在,为什么我认为这是可能的,这与传递给ArrayAdapter的构造函数(context,resource,textViewResourceId,data array)非常相似,我认为ArrayAdapter也必须使用LayoutInflater只给出了一个Context。

But how can it be done? 但怎么办呢?


解决方案:

参考一: https://en.stackoom.com/question/9HUb
参考二: https://stackoom.com/question/9HUb
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部