码迷,mamicode.com
首页 > 其他好文 > 详细

解决adapter中使用ViewHolder出现重复加载的问题

时间:2014-10-17 20:18:02      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   使用   sp   div   

   Map<Integer, View> map = new HashMap<Integer, View>();

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder viewHolder = null;
        if (map.get(position) == null) {
            viewHolder = new ViewHolder();
            view = View.inflate(context, R.layout.setting_item, null);
            viewHolder.portrait = (ImageView) view.findViewById(R.id.portrait);
            viewHolder.divider = (View) view.findViewById(R.id.divider);
            viewHolder.text = (TextView) view.findViewById(R.id.tv_item_name);
            viewHolder.more = (ImageView) view.findViewById(R.id.set_more);
            map.put(position, view);
            view.setTag(viewHolder);
        } else {
            view = map.get(position);
            viewHolder = (ViewHolder) view.getTag();
        }
        if (position == 0) {
            viewHolder.portrait.setVisibility(ImageView.VISIBLE);
        }
        if (position == 4 || position == 5) {
            viewHolder.more.setImageResource(R.drawable.ok_icon);
        }
        if (position == 2 || position == 5) {
            viewHolder.divider.setVisibility(View.VISIBLE);
        }
        viewHolder.text.setText((String) itemList.get("name" + position));

        return view;
    }

    private class ViewHolder {
        private TextView text;
        private ImageView portrait;
        private View divider;
        private ImageView more;
    }

 

解决adapter中使用ViewHolder出现重复加载的问题

标签:style   blog   color   io   os   ar   使用   sp   div   

原文地址:http://www.cnblogs.com/iiahadadiaow/p/4031809.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!