Edw*_*Lee 218 android listview listadapter
我正在编写ListAdapter的自定义实现.
在它的构造函数中,我接受一个Context,一个资源ID(即代表布局文件的R.id.xxx),一个列表和一个map(这些包含数据).
现在,问题是我需要一个LayoutInflater来获取View对象,该对象位于单独的布局XML文件中.
如果只给出Context,我怎样才能获得LayoutInflater?
现在,为什么我认为这是可能的,这与传递给ArrayAdapter的构造函数(context,resource,textViewResourceId,data array)非常相似,我认为ArrayAdapter也必须使用LayoutInflater只给出了一个Context.
但怎么办呢?
Dav*_*ebb 503
您可以使用该类中的static from()方法LayoutInflater:
LayoutInflater li = LayoutInflater.from(context);
Run Code Online (Sandbox Code Playgroud)
Ngu*_*Dat 53
您还可以使用此代码来获取LayoutInflater:
LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)
Run Code Online (Sandbox Code Playgroud)