Android ListView 使用HashMap解决复用问题


public class MyAdapter extends BaseAdapter {

   ......
    private HashMap, View> hm = new HashMap, View>();

   ......
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        
        ViewHolder holder = null;
        if (hm.get(position) == null) {
            convertView = View.inflate(context, R.layout.item, null);
            holder = new ViewHolder();
           ......
            convertView.setTag(holder);
            hm.put(position, convertView);
        } else {
            convertView = hm.get(position);
            holder = (ViewHolder) convertView.getTag();
        }
       ......
        return convertView;
    }

    class ViewHolder {
        ......
    }
}

你可能感兴趣的:(学习日记)