android - OutOfMemoryError when doing setImageResource() -


imageview.setimageresource(int id); showing outofmemoryerror. have tablelayout in adding tablerow pragmatically, in each row i'm setting image, in projects resource folder, referencing image withe resource_id.

private void additems() {     table.removeallviews();     random rand = new random();      (int = 0; < 20; i++) {         tablerow row = new tablerow(getactivity());         table.addview(row);          relativelayout profile = (relativelayout) getlayoutinflater(null).inflate(r.layout.buddyname, null);         textview name = (textview) profile.findviewbyid(r.id.name);         name.settext(randomnames[i]);          imageview photo = (imageview) profile.findviewbyid(r.id.photo);         photo.setimageresource(randomphoto[new random().nextint(randomphoto.length - 1)]);         row.addview(profile);     } }   

each time doing table.removeallviews(); not working, can guess because image resource loading again , again on heap , not clearing heap, can reference loaded image, there solution.

buddyname? seems contact list. if is, use listview instead. dynamically loads elements visible. 20 table rows indeed much.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -