我是Android编程的新手。我正在使用不同类型的行在ListView上进行示例。我创建了一个从ArrayAdapter扩展的CustomAdapter
public class CustomAdapter extends ArrayAdapter<String> {
public static final int TYPE_ODD = 0;
public static final int TYPE_EVEN = 1;
public static final int TYPE_WHITE = 2;
public static final int TYPE_BLACK = 3;
private final Context context;
private final int resource;
private ListViewItem[] objects;
public CustomAdapter(Context context, int resource, ListViewItem[] objects) {
super(context, resource, objects);
this.context = context;
this.resource = resource;
this.objects = objects;
}
Eclipse显示超级(上下文,资源,对象); line as error“构造函数ArrayAdapter(Context,int,MainActivity.ListViewItem [])未定义”
我无法弄清楚为什么会这样。请帮忙。
答案 0 :(得分:2)
尖括号(<String>
)中的数据类型需要与您提供的数组中的数据类型匹配(ListViewItem[]
)。在你的情况下,他们没有。
最有可能的是,你应该:
将其设为ArrayAdapter<ListViewItem>
删除private ListViewItem[] objects
,因为它是不必要的并且会让您遇到麻烦 - 使用getItem()
从超类访问数组
最有可能的是,你也不需要private final int resource
,因为你不太可能会使用它,尽管我不能排除它。
答案 1 :(得分:1)
public class CustomAdapter extends ArrayAdapter<ListViewItem> {
public static final int TYPE_ODD = 0;
public static final int TYPE_EVEN = 1;
public static final int TYPE_WHITE = 2;
public static final int TYPE_BLACK = 3;
private final Context context;
private final int resource;
private ListViewItem[] objects;
public CustomAdapter(Context context, int resource, ListViewItem[] objects) {
super(context, resource, objects);
this.context = context;
this.resource = resource;
this.objects = objects;
}
----------
see the first line of answer just change this line
public class CustomAdapter extends ArrayAdapter<String>
to
public class CustomAdapter extends ArrayAdapter<ListViewItem>