Working with Lists

When you have a list (it can be empty, too), you can do something with it. For starters, you can add a new item to the end of the list. If the list had n items before, then after you add the new one, it will have n+1 items; the last item will be item number n+1. This is done with the block add items to list.

You can get the number of items in the list using the length of list block. It’s often useful to know how long a list is so you don’t try to ask for data that’s not there. If you ever ask for an item that doesn’t exist, the app will create an error, which the user will see. For example, if a list has five items and you try to get item number 6 (or higher), that item doesn’t exist and thus will trigger an error. Try not ...

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.