I download photos from the Internet. have a site on the same page which has 18 photos (80x60 px ~ 10kb).
so I made a list which loads the new picture (sleduyuschuyuyu page) the problem is when I load three or more pages, a memory error occurs the question is how to get rid of?
Now I build an array of bitmaps
for (Element titles : title) {
if (titles.children().hasClass("btl")){
m = new HashMap<String, Object>();
m.put(MyActivity.ATTRIBUTE_NAME_TEXT, titles.select("a[href]").attr("abs:href"));
Picasso p = Picasso.with(MyActivity.context);
m.put(MyActivity.ATTRIBUTE_NAME_PHOTO,Bitmap.createScaledBitmap(p.load(titles.select("img").attr("abs:src")).get(),80,60, true) );
data.add(m);
}
}
and in adapter
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
final Map<String, Object> itemData = datas.get(position*2);
final Map<String, Object> itemData2 = datas.get(position*2+1);
Bitmap bitmap2 = null;
Bitmap bitmap = (Bitmap) itemData.get("img");
if(itemData2!=null)
bitmap2 = (Bitmap) itemData2.get("img");
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.items, null, true);
holder = new ViewHolder();
holder.ivImage = (ImageView) rowView.findViewById(R.id.imageView);
holder.ivImage2 = (ImageView) rowView.findViewById(R.id.imageView1);
rowView.setTag(holder);
} else {
holder = (ViewHolder) rowView.getTag();
}
holder.ivImage.setImageBitmap(bitmap);
holder.ivImage2.setImageBitmap(bitmap2);
holder.ivImage.setTag(position*2);
holder.ivImage2.setTag(position*2+1);
holder.ivImage.setOnClickListener(this);
holder.ivImage2.setOnClickListener(this);
return rowView;
}
I was offered to save images in the cache and load them from there but do not know how to do it.
please help