开发者

ListAdapter Item ViewType

I have just found the possibilty to determine a type of a list entry with the getItemViewType() of the adpater. Can you provide me with a description on how to use this properly?

Currently I use a custom type integer in the view classes that I use to create the views in the getView() of the list adapter. Is it a better solution to use the built in capbilities of the adapter?

My current code:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    IFilterable data = filteredData.get(position);
    if(convertView == null || convertView.getId() != data.getType()) {
        switch(data.getType()) {
            case IReport.SPECIAL_ACTION:
                convertView = new SpecialActionView(context);
                ((SpecialActionView) convertView).set(((SpecialAction) data));
                break;
            case IReport.TRANSFER_DECLARATION:
                convertView = new TransferDeclarationView(context);
                ((TransferDeclarationView) convertV开发者_JS百科iew).set(((TransferDeclaration) data));
                break;
        }
    }
    return convertView;
}


I think your code is ok, take a look at this video for more informations.


I believe this value is used internally by the UI when recycling views, to reduce the amount of View re-inflation.

You might want to look at AgendaByDayAdapter.java for an example of its usage

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜