Volley Plus OutOfMemoryError in List Adapter

后端 未结 3 1740
刺人心
刺人心 2021-01-26 08:51

I am using Volley Plus library. I am showing ListView with image and text view with no error, but when i scroll up and down lots of time in this listview it get

3条回答
  •  迷失自我
    2021-01-26 09:06

    The problem is that you keep loading images but the memory they fill isn't released afterwards. You could simply if you are recycling a row test if the image is a bitmap and then call recycle() on it. You might use something like this:

    if (rowView == null) {
            LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            rowView = inflater.inflate(R.layout.list_row_item_products, null);
    
            ViewHolder viewHolder = new ViewHolder();
            viewHolder.title = (TextView) rowView.findViewById(R.id.tvName);
            viewHolder.image = (ImageView) rowView.findViewById(R.id.list_image);
    
            rowView.setTag(viewHolder);
    }
    else {
        ViewHolder holder = (ViewHolder) rowView.getTag();
        if(holder.image.getDrawable() instanceof BitmapDrawable)
            ((BitmapDrawable) holder.image.getDrawable).getBitmap().recycle();
    }
    

提交回复
热议问题