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