如何获取布局气筒给定一个上下文? [英] How to Get a Layout Inflater Given a Context?

查看:120
本文介绍了如何获取布局气筒给定一个上下文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个自定义实现一个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.

但怎样才能做到呢?

推荐答案

您可以使用静态 <一个href="http://developer.android.com/intl/de/reference/android/view/LayoutInflater.html#from%28android.content.Context%29"><$c$c>from() LayoutInflater 类方式:

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

 LayoutInflater li = LayoutInflater.from(context);

这篇关于如何获取布局气筒给定一个上下文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆