0

我使用带有回收视图(支架)的适配器。这是代码:

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

    ViewHolder holder;

    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.playlists_item, null);

        holder          = new ViewHolder();

        holder.picture  = (ImageView)   convertView.findViewById(R.id.playlist_picture);
        holder.name     = (TextView)    convertView.findViewById(R.id.playlist_name);
        holder.desc     = (TextView)    convertView.findViewById(R.id.playlist_desc);
        holder.play_bt  = (ImageView)   convertView.findViewById(R.id.playlist_play);

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

    holder.picture.setImageResource(R.drawable.placeholder);

    ...

if(messages.get(position).containsKey("IMAGE"))
            {
                if(global.isInCache(messages.get(position).get("IMAGE")))
                    holder.picture.setImageBitmap(global.getBitmap(messages.get(position).get("IMAGE")));
                else{
                    holder.picture.setTag("http://**********" + messages.get(position).get("IMAGE"));
                    new loadImageTask().execute(holder.picture,cache,messages.get(position).get("IMAGE"),"********/upload/********/");
                }
            }

这是我的下载器:

public class loadImageTask extends AsyncTask< Object , Void, Void>
{
    ...

    @Override
    protected void onPreExecute() {

    }

    @Override
    protected Void doInBackground(Object... params) {
        imagem = (ImageView) params[0];
        image_tag = (String)imagem.getTag();
        caminho = (String) params[3];
        name = (String) params[2];
        imgLoad = LoadImageFromWeb(caminho+name);

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {

        if (imgLoad instanceof BitmapDrawable) { 
            bitmap = ((BitmapDrawable)imgLoad).getBitmap();
        }

        bitmap = getResizedBitmap(bitmap, 100, 100);

        global.putCache(name, bitmap);

        imagem.setImageBitmap(bitmap);
    }
}

事实证明,当我在listview下载完成后滚动时,它image会加载到我可见的位置(并且在快速滚动时的相同位置,listview每次下载完成时总是会更改图像)。

我希望,如果您正在下载要完成的图像的位置不再可见,那就没有完成setImageBitmap

4

1 回答 1

0

试试 Picasso 或 Glide 库

     Picasso.get().load(url)
     .placeholder(R.drawable.iconname)
     .error(R.drawable.iconname)
      .into(/*your image view*/);

    Glide.with(context)
     .load("http://inthecheesefactory.com/uploads/source/glidepicasso/cover.jpg")
     .into(ivImg);
于 2018-10-16T16:40:21.620 回答