Skip to content

Get item view type iterates all items #4

@abdurahmanadilovic

Description

@abdurahmanadilovic

I noticed this code in the GenericAdapter

  @Override
    public int getItemViewType(int position) {
        Class<?> lItemClass = mObjectList.get(position).getClass();
        for (int i = 0; i < mModels.size(); i++) {
            if (mModels.get(i).getItemType().equals(lItemClass)) {
                return i;
            }
        }
        return -1;
    }

Why is it necessary to iterate over all items to get item type? And why do you return an item position as item view type? Since items of different types can be non sequential positions like [type1, type2, type1, type2], it would be easier to just get an item and return item.getType() method result.

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions