Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many items a ListView can store?

I'm new to Android programming. I wonder how many items a ListView can store? I search in docs but they don't talk about this. What if I put a lot (maybe 10k) items into a ListAdapter, will it affect to the performance?

Cheers, MK.

like image 420
Minh Kiet Avatar asked Feb 09 '11 11:02

Minh Kiet


2 Answers

The ListView is virtualized in Android. Practically speaking, that means that there's no actual limit for the number of elements inside it. You can put millions of rows inside the list and it'll only allocate memory for the currently visible ones (or a few more tops).

Check out the dozens of tutorials regarding writing a custom Adapter class for an AdapterView (ListView extends that). Also check out the Google I/O 2010 session on ListViews; it's really useful: here

like image 90
Zsombor Erdődy-Nagy Avatar answered Sep 19 '22 12:09

Zsombor Erdődy-Nagy


There's no limit as the ListView only renders items when they come into view, and so only cares about the data for the ListView when it comes to render the item (though it needs to know the quantity of items to render the scrollbar correctly)

The Google IO video really is great for learning about ListView http://www.youtube.com/watch?v=wDBM6wVEO70

That said, I'd ask whether you SHOULD load that many, as clearly the user cannot look at them all and scrolling around a ListView with that many items will be very tedious. If it was me I'd be asking some questions:

  • Does the list need to show them ALL initially? Can it just show the most relevant set? The nearest/biggest/smallest/best/etc
  • Rather than load them all at once, can you load blocks in pages of items? So for example you load 10-100 initially, and when the user gets to the bottom show "Loading more..." with a progress spinning icon, and pull more in, then the user can choose how many to load, and how much scrolling they are prepared to do
  • Should you be building a UI to filter the items so there's never a need for them to look at 10,000?

More on ListView http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/ http://developer.android.com/guide/topics/ui/binding.html http://www.androidguys.com/2008/07/14/fancy-listviews-part-one/

like image 32
Ollie C Avatar answered Sep 20 '22 12:09

Ollie C