user2074331
user2074331

Reputation: 31

Recycle views in scrollview in android

I have a scrollview in which I have inflated the view dynamically (same as facebook wall of android app, there is an imageview and textview in it.).
All the images are dynamic. If I load too much data in it then I get outofmemory exception. I know that listview will solve my problem but I cannot use the listview.
So, is there any way to optimize i.e recycle the views when they are not visible?

Upvotes: 3

Views: 2208

Answers (2)

Brajendra Pandey
Brajendra Pandey

Reputation: 2274

you can not handle Errors in normal circumstance but you can use following techneques to remove thias errror
1-Please clear your Arraylist before item add .
2-Use garbage collection techniques 
System.gc() or finalize method use for Memory reclaim from object.

Upvotes: 1

Pedro Loureiro
Pedro Loureiro

Reputation: 11514

By your comments, I believe you still can use a list view:

A listview can have many different kinds of view. For more information on this, read Android ListView with different layouts for each row.

This way, views will be recycled and hopefully your memory usage will be smaller.

Anyway, I would probably investigate your code as I guess that for running out of memory, you probably are leaking objects or doing something way too many times than needed.

Upvotes: 2

Related Questions