I have a scenario where I’m coding a ScrollView which is intended to act as an “infinite scroll,” dynamically adding more views to itself to grow the size as the user scrolls down (just like scrolling down your Facebook timeline). Each view that is added is a complex component containing a few TextViews, ImageViews, etc.
It should be no surprise that memory has quickly become an issue, especially once we reach the 50+ elements range. Before long, I’m getting serious OutOfMemoryErrors.
On iOS, I would simply use a UITableView, which solves the problem by removing views which are not on the screen and reusing their containers (eg, even with 100+ views in the table, you’ll only actually have a handful ever being drawn).
Is there some similar technique or other good solution to accomplish this on Android?
Yes there is a pattern for efficient listview usage. There is great recording about that pattern from a Google IO presentation done by Romain Guy from 2010 that is still valid. Otherwise it is also documented in all sorts of places – just google for “android holder listview pattern”