Android custom arrayadapter constructor issue

删除回忆录丶 提交于 2020-01-25 00:12:07

问题


I am making a custom arrayAdapter for my listview, but a simple thing like my super constructor is messing me up!

private ArrayAdapter<ScheduleTime> timeHold;
    //make proper constructor, see use ticket types
    public TimeTableAdapter(Context context, int textViewResourceId,
            ArrayAdapter<ScheduleTime> timesTable) {
        super(context, textViewResourceId, timesTable);
        this.timeHold = timesTable;
    }

I get the error on the super line:

super(context, textViewResourceId, timesTable);

The constructor SimpleAdapter(Context, int, ArrayAdapter<ScheduleTime>) is undefined

What am I missing here? my above constructor clearly has all of those elements


回答1:


Just because the constructor you are defining takes a certain parameter list, it doesn't mean the super class has that constructor. After all, you can define any arbitary parameter list for your constructor.

The super constructor you are trying to call is closest to ones in the ArrayAdapter class, but the error message suggests you are trying to inherit from SimpleAdapter. Have you got this right? If it should be ArrayAdapter, the last argument needs to be the array (or List) of the objects which back the adapter, instead of just a single object of that type.

If it is SimpleAdapter, the only constructor is here, which looks quite a bit different.




回答2:


super is used to call the constructor of the superclass, the class you're extending. Look at the documentation: the constructor of SimpleAdapter has different arguments.



来源:https://stackoverflow.com/questions/7099901/android-custom-arrayadapter-constructor-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!