2 u011325156 u011325156 于 2016.04.19 15:37 提问

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;
}

2个回答

u011325156
u011325156   2016.04.19 17:09
已采纳

找到原因了,加载图片时因为有异步加载,所以无论是加载网络图片还是本地图片都应该使用一种加载方式

CSDNXIAOD
CSDNXIAOD   2016.04.19 15:51

Android ListView滑动过程中图片显示重复错乱闪烁问题解决
Android ListView滑动过程中图片显示重复错乱闪烁问题解决
Android ListView滑动过程中图片显示重复错位闪烁问题解决
----------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!

Csdn user default icon
上传中...
上传图片
插入图片