Custom android adapter with generic class

和自甴很熟 提交于 2019-12-06 07:26:27

You cannot keep only one instance of ViewHolder. You need to create new object everytime the convertView is null and setTag.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    View v = convertView;
    ViewHolder h;
    if (v == null) {
        v = inflater.inflate(resources, parent, false);
        h = new ViewHolder();
        listener.init(v, h);
        v.setTag(h);
    } else {
        h = (ViewHolder) v.getTag();
    }
    T object = (T) getItem(position);
    listener.execute(object, h);
    return v;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!