Lists that Expand on Demand

In most of this book, we’ve kept all our data either in properties of components or in global variables. These work great, but they have a limitation: They can’t expand. Sometimes we don’t know how much information we will need to store, and that’s another great use for lists.

The one-dimensional list we discussed earlier in this chapter is perfect for when we need our information to grow. With just one list, we can store any number of items in it.

Consider the contacts app we started imagining in the last section. The user might have 5 friends, or 50, or 500; our app should be able to handle all of them with no problem.

Clearly, we can’t make a global variable for each contact. We can’t guess how many friends the ...

Get Learning MIT App Inventor: A Hands-On Guide to Building Your Own Android Apps now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.