构造函数ArrayAdapter&LT;串GT;未定义 - 超()标记 [英] The constructor ArrayAdapter<String> is undefined - super() marked
问题描述
我此刻有些无奈。
我有以下code
public class ListViewAdapter<String> extends ArrayAdapter<String> {
private final Context context;
private final int textViewResourceId;
private final int[] itemResourceIds;
private final ArrayList<String> list;
public ListViewAdapter(Context context, int textViewResourceId,
int[] itemResourceIds, ArrayList<String> list) {
super(context, textViewResourceId, itemResourceIds, list);
this.context = context;
this.textViewResourceId = textViewResourceId;
this.itemResourceIds = itemResourceIds;
this.list = list;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// some code...
}
}
但是Eclipse标志着超(...)行,我想不通为什么。
But eclipse marks the super(...) line, and I can't figure out why.
它告诉我:
The constructor ArrayAdapter<String>(Context, int, int[], ArrayList<String>) is undefined
但我没有这样准确界定呢?
But didn't I define it exactly this way?
请帮我在这里。
推荐答案
当您使用超强,你必须调用父类的构造函数中定义的一个
when you use super, you have to call one of the parent class defined constructors
ArrayAdapter,你可以看到<一个href=\"http://developer.android.com/reference/android/widget/ArrayAdapter.htmlhttp://developer.android.com/reference/android/widget/ArrayAdapter.html\"相对=nofollow>这里,有这样可用的构造函数:
ArrayAdapter, as you can see here, has this available constructors:
ArrayAdapter(Context context, int resource)
ArrayAdapter(Context context, int resource, int textViewResourceId)
ArrayAdapter(Context context, int resource, String[] objects)
ArrayAdapter(Context context, int resource, int textViewResourceId, String[] objects)
ArrayAdapter(Context context, int resource, List<String> objects)
ArrayAdapter(Context context, int resource, int textViewResourceId, List<T> objects)
所以,你必须给他们打电话之一
So you have to call one of them
和你调用
超(背景下,textViewResourceId,itemResourceIds,清单);那是
ArrayAdapter(上下文,INT,INT [],ArrayList中),而且不存在。
super(context, textViewResourceId, itemResourceIds, list); that is ArrayAdapter(Context, int, int[], ArrayList) and does not exists.
,而不是一个int数组, itemResourceIds
应该是一个int。
instead of an array of int, itemResourceIds
should be an int.
如何解决它取决于什么是itemResources的内容[];
How to fix it depends on what are the contents of itemResources[];
认为这样的:
ArrayAdapter(Context context, int resource, int textViewResourceId, List<String> objects)
接收XML布局文件的ID,然后文本字段的ID。
receives the id of an xml layout file, and then the id of a text field.
这
ArrayAdapter(Context context, int resource, List<T> objects)
接收XML文件的仅仅是ID
receives just the id of the xml file
也许你可能想只是叫
super(context, itemResourceIds[0],textViewResourceId, list);
或只是
super(context, itemResourceIds[0], list);
但要看是什么 itemResourceIds
的内容居然都是。
如果您正在实现整个适配器,你不是真的关心你传递给家长什么ID,所以你可以简单地将其更改为
If you are implementing the whole adapter, you dont really care about what id you are passing to the parent, so you can simply change it to
super(context, 0, list);
由于在父类没有人goint使用它。
since in the parent class nobody is goint to use it.
不管怎么说,如果你是goint自己来实现的一切,你可以考虑延长 BaseAdapter
而不是 ArrayAdaper
自BaseAdapter犯规需要在构造函数中的任何参数,而且很可能你不需要一个ArrayAdapter的任何功能。
Anyways, if you are goint to implement everything by yourself, you can consider extending BaseAdapter
instead of ArrayAdaper
since BaseAdapter doesnt need any parameter in the constructor, and probably you dont need any functionality of the ArrayAdapter.
这篇关于构造函数ArrayAdapter&LT;串GT;未定义 - 超()标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!