问题描述
- android Listview显示图片不正确问题
-
Listview有5条数据,但是每次加载完,第一个item显示的图片都是最后一条数据的图
片,刷新之后正常,怎样才能让第一条显示正确?下面是我getview方法的内容,希望各位帮忙看下!
public View getView(int position, View contentView, ViewGroup arg2) {
HelpHolder holder = null;
if (null == contentView) {
holder = new HelpHolder();
contentView = LayoutInflater.from(mcontext).inflate(
R.layout.ranking_list_item, null);holder.rank = (TextView) contentView .findViewById(R.id.rank_item_number);; holder.name = (TextView) contentView .findViewById(R.id.rank_item_name); holder.score = (TextView) contentView .findViewById(R.id.rank_item_score); holder.image = (ImageView) contentView .findViewById(R.id.rank_uer_avatar); contentView.setTag(holder); } else { holder = (HelpHolder) contentView.getTag(); } if (position == 0) { holder.rank.setBackgroundResource(R.drawable.bg_rank1); holder.rank.setTextColor(Color.parseColor("#ffffff")); } else if (position == 1) { holder.rank.setBackgroundResource(R.drawable.bg_rank2); holder.rank.setTextColor(Color.parseColor("#ffffff")); } else if (position == 2) { holder.rank.setBackgroundResource(R.drawable.bg_rank3); holder.rank.setTextColor(Color.parseColor("#ffffff")); } else { holder.rank.setBackgroundResource(R.drawable.bg_rank); holder.rank.setTextColor(Color.parseColor("#A98F52")); } holder.image.setTag(ranklist.get(position).getRank()); holder.image.setImageResource(R.drawable.ph_user); holder.name.setText(ranklist.get(position).getUserName()); holder.rank.setText(ranklist.get(position).getRank() + ""); holder.score.setText(ranklist.get(position).getScore()); if (holder.image.getTag().equals(position+1)&& holder.image.getTag() != null) { if (ranklist.get(position).getAvatar() != null && !ranklist.get(position).getAvatar().equals("")) { Log.d("tags-000-----====-------",position+"----"+ranklist.get(position).getAvatar()); imageloader.displayImage(ranklist.get(position).getAvatar(), holder.image,options); }else{ Log.d("tags-1111----====-------",position+"----"); holder.image.setImageResource(R.drawable.ph_user); } } return contentView; }
解决方案
找到原因了,加载图片时因为有异步加载,所以无论是加载网络图片还是本地图片都应该使用一种加载方式
解决方案二:
Android ListView滑动过程中图片显示重复错乱闪烁问题解决
Android ListView滑动过程中图片显示重复错乱闪烁问题解决
Android ListView滑动过程中图片显示重复错位闪烁问题解决
时间: 2024-11-03 20:28:11