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;
}
找到原因了,加載圖片時因為有異步加載,所以無論是加載網絡圖片還是本地圖片都應該使用一種加載方式