android如何设置以编程方式准备的arrayAdapter布局

问题描述:

我正在尝试将自定义列表视图与阵列适配器一起使用.我有这个适配器的布局.但我想以编程方式创建这个适配器的布局.Arrayadapter 将此布局的 id 传递给它的超级.它不接受布局.如何传递布局对象而不是 resourceId?

I am trying to use custom listview with an arrayadapter. I have a layout for this adapter.But I want to create layout of this adapter programmatically.Arrayadapter pass the id of this layout to its super. It doesnt accept layout. How can I pass the layout object instead of resourceId?

super(context, LayoutResourceId, ArrayList);

super(context, LayoutResourceId, ArrayList);

对于 ArrayAdapter,您可能不需要扩展它,只需实例化它并使用它...使用此构造函数:http://developer.android.com/reference/android/widget/ArrayAdapter.html#ArrayAdapter(android.content.Context, int, int)

for the ArrayAdapter you might not need to extend it, just instantiate it and use it...use this constructor: http://developer.android.com/reference/android/widget/ArrayAdapter.html#ArrayAdapter(android.content.Context, int, int)

new ArrayAdapter(context, layoutResourceId,arrayList);