繁体   English   中英

构造函数在Custom ArrayAdapter中未定义

[英]Constructor is undefined in Custom ArrayAdapter

我知道这已经解决了一百万次了,是的,我已经搜索过了,但是对我来说不起作用。

问题在于方法super不需要适当的参数。

编码:

public class QuotesArrayAdapter extends ArrayAdapter<Map<Integer,List<String>>> {
private Context context;
Map<Integer,List<String>> Values;
static int textViewResId;
Logger Logger;

public QuotesArrayAdapter(Context context, int textViewResourceId, Map<Integer,List<String>> object) {
    super(context, textViewResourceId, object);   //<---- ERROR HERE
    this.context = context;
    this.Values = object;
    Logger = new Logger(true);
    Logger.l(Logger.TAG_DBG, "ArrayAdapter Inited");
}

Eclipse说了什么:

Multiple markers at this line
- The constructor ArrayAdapter<Map<Integer,List<String>>>(Context, int, Map<Integer,List<String>>) 
 is undefined
- The constructor ArrayAdapter<Map<Integer,List<String>>>(Context, int, Map<Integer,List<String>>) 
 is undefined

它想要super(Context,int) ,那不是我想要的

查看可用于ArrayAdapter的构造函数。

ArrayAdapter(Context context, int textViewResourceId)
ArrayAdapter(Context context, int resource, int textViewResourceId)
ArrayAdapter(Context context, int textViewResourceId, T[] objects)
ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects)
ArrayAdapter(Context context, int textViewResourceId, List<T> objects)
ArrayAdapter(Context context, int resource, int textViewResourceId, List<T> objects)

这些都不符合您的论点。

您打算调用哪一个? 这里的TMap<Integer,List<String>> ,但是构造函数的object参数正是该类型。 如果要使用需要集合的构造函数之一,则需要从已有的单个对象构建该集合。

最简单的方法可能只是使用:

public QuotesArrayAdapter(Context context, int textViewResourceId,
                          Map<Integer,List<String>> object) {
    super(context, textViewResourceId);
    add(object);
    ...
}

很简单, ArrayAdapter中没有构造函数需要Map。

您需要将其转换为List或基本数组,如果这些选项都不起作用,则必须扩展BaseAdapter

另外,您可以使用Arrays.asList(..)

public QuotesArrayAdapter(Context context, int textViewResourceId, Map<Integer,List<String>> object) {
    super(context, textViewResourceId,  Arrays.asList(object));   
.... 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM