首页 > 代码库 > 解决adapter中使用ViewHolder出现重复加载的问题
解决adapter中使用ViewHolder出现重复加载的问题
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出现重复加载的问题
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。