views:

103

answers:

3

When I have a ListActivity and an Adapter how does Android handle a list with 200 elements. Does it try to load all of them directly how does it wait till the user scrolls and then renders those elements?

Do I have to worry with performance when a list is too long?

+1  A: 

Depends how are the adapters implemented.

If you have an adapter that is not subclassed (you use one that is provider by SDK) Android will try to load all of them directly.

I recommend to subclass SimpleCursorAdapter and implement your custom adapter. This way you will have for example 10 views (as many your screen needs), and the view it will be reused for the rest of the 190 records.

Pentium10
That's not correct - it doesn't depend on Adapter implementation. It is a mechanism in AbsListView and AbsSpinner, that recycles the list item View-s.
ognian
A: 

I'm not sure how Android handles it internally. But most programs I've seen handle the issue by loading 20 or so items and then making the last item say "Load next 20 items". Then when you click it, it loads the next 20 items.

Slapout
That's basically the question. Do I have to do something like that or can I simply trust Android to work without me having to implement something like that.
Christian
+1  A: 

There are several parts to this question. First of all, the data itself. Is that coming from a SQLite database via a query? If so, you have a Cursor object, which contains the entire result. So if you have a query that yields 200 rows, you will have all 200 rows in memory (which is why it's so important to narrow your projection).

As for the list itself, that part is pretty efficient - Android will only create views for the elements that you can actually see. And, depending on what kind of views you have, and whether they support recycling, Android will actually recycle existing objects to minimize the amount of overhead for initialization and memory management.

EboMike