aloneGirle
2016-04-19 07:37
采纳率: 42.1%
浏览 1.6k

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;
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • aloneGirle 2016-04-19 09:09
    已采纳

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

    点赞 评论

相关推荐 更多相似问题