Android – listview and volleyball – image misallocation

I am using the volley library to load images from the Internet. I have a list view. Some rows are loaded using volley's Library "networkimageview", and others are loaded by static resources

There seems to be something wrong because I have the wrong line of the image

I have an arrayadapter, where you have my getview method:

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    ViewHolder holder;

    House house = houses.get(position);

    if (convertView == null) {
        LayoutInflater inflater = ((Activity)getContext()).getLayoutInflater();
        convertView=inflater.inflate(this.layout, parent, false);

        holder=new ViewHolder();
        holder.image=(NetworkImageView) convertView.findViewById(R.id.imageView1);
        holder.name=(TextView) convertView.findViewById(R.id.housename_listelement_houseslist);
        holder.rating=(TextView) convertView.findViewById(R.id.houserating_listelement_houseslist);         

        convertView.setTag(holder);

    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    if(house.getUrl()!=null){
        String url=house.getUrl();
        holder.image.setImageUrl(url, ((TopHousesListViewPager)getContext()).mImageLoader);
    }else{
        holder.image.setBackgroundResource(R.drawable.defaulthouse);
    }


    holder.name.setText(house.getName());
    holder.rating.setText(String.format("%.2f",house.getRate()));
return convertView;
}

As you can see, if my object has a URL, I will only display images from the Internet, but I am looking at those lines where the object has no URL but the image comes from other lines

Suggestions?

thank you!

resolvent:

As @ Selvin said: you must reset the picture URL every time you get the holder:

    } else {
        holder = (SuggestionViewHolder) convertView.getTag();
        holder.image.setImageUrl(null, imageLoader);
    }

    if(house.getUrl()!=null){
       String url=house.getUrl();
       holder.image.setImageUrl(url, ((TopHousesListViewPager)getContext()).mImageLoader);
    } else {
       holder.image.setBackgroundResource(R.drawable.defaulthouse);
    } 

It works for me

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>