I have a custom ArrayAdapter
that is used to place icons within lists
public class IconArrayAdapter extends ArrayAdapter<IconListItem> {
protected int resource;
public IconArrayAdapter(Context context, int resource, ArrayList<IconListItem> items) {
super(context, resource, items);
this.resource = resource;
}
public IconArrayAdapter(Context context, ArrayList<IconListItem> items) {
super(context, R.layout.icon_list_item, items);
this.resource = R.layout.icon_list_item;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
IconListItem iconItem = getItem(position);
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(this.resource, null);
}
...
return convertView;
}
}
This is a generic adapter I use in multiple part of my app that I need to extend a little bit in one spot for a more specific purpose. I started building the extended class but immediatley ran into a problem
public class TeamListArrayAdapter extends IconArrayAdapter {
public TeamListArrayAdapter(Context context, ArrayList<TeamListItem> items) {
super(context, R.layout.team_list_item, items);
}
}
Despite TeamListItem
extending IconListItem
, I am unable to pass the items into the super. From my understanding, because TeamListItem
extends IconListItem
I should be able to pass that, but clearly I can't. What am I misunderstanding here?
Edit: I guess I'm a little confused because I can easily do things like:
private class Object1 {
protected int property1 = 1;
}
private class Object2 extends Object1 {
protected int property2 = 2;
}
ArrayList<Object1> objects = new ArrayList<Object1>();
objects.add(new Object2());
With no problem.
Edit 2: Added a code for the IconArrayAdapter that has the private bits removed.