List Blocks On App Inventor

List is a necessity in almost every app regardless of what programming language you use. This is the easiest way to create and manipulate a set of values/items/elements in an ordered fashion. Please go over the reference before we start. In this tutorial, we will learn how to create a list, add new items to a list, display list items, replace an item in the list, remove an item or remove everything from a list, search for an item, and sort a list.


The snapshot below is from our tutorial app. I recommend you to download the source of this application ListBlocks and try it on an emulator or on a device so you will have better understanding of list manipulation. In the source, I have added plenty of comments for you to easily understand the implementation. You should be able to see those comments once you load the source in your block editor window.  
I tried to keep the source as clean as possible without optimizing it too much for beginners to understand. Once you understand the application, trust me, you will be able to rearrange the pieces in more efficient way. Also, for some operations I tried to control it through block editor which actually you can control from designer window like checking if a text box contains only numbers which you can do by enabling the NumbersOnly option in the designer window for a TextBox component, you can specify a ListPicker’s elements through ElementsFromString property in the designer window which I also implemented from block editor window. The purpose of that is to give you alternative ideas which you may need in the future. Also note that 1 and 1.25 are both numbers while list indexes are referred by only whole numbers.
List app snapshot Note that the comments in yellow in the image above are not part of the application.
1. Create a List
2. Add Items to a List
3. Display List Items
4. Remove List Items
5. Replace an Item
6. Search for an Item
7. Sort a List
8. Shuffle a List  
1. Create a List
Creating a list is as simple as this-
Make empty lists
We have just created four empty lists above, named list1, list2, list3, and userList. “create empty list” block can be found in Lists drawer in your blocks editor. Those lists are currently empty as we haven’t added any items yet. Note, you can also use “make a list” block to create an empty list. Just don’t put any item when using “make a list” block for creating empty list like this-     
Empty list
What if you don’t want to create an empty list, rather you want to create a list with items in it? Well, no worries. You can use “make a list” block to do so.  
Make a list with items  
In the above image, we used “make a list” block to create a list named myList with three items – Apple, Banana, and Guava. If we didn’t put any item in the make a list block, it would create an empty list just like the way we did with create empty list block. Note that, you can put as many items as you want in make a list.  
Tips: When you name a variable, try naming it with a purpose. Say you need a list of prices of different fruits, you can name that list variable – fruitsPriceList so that later you don’t have to recall the purpose of that list, specially when you have lots of variables in your block editor. Also by the name of the variable, one should know that variable represents a list.  
2. Add Items to a List  
Adding an item can be done different ways.           
If you look at the image above, we have populated all three lists with different items. First one will have a list of three items which are Orange, Apple, and Banana; the second one is consisted of another three items – 20, 30, and 10. The last one, list3 is consisted of two items which are actually lists. Yes, you can have a list of lists. If you take the first item from list3 which is also a list, you will get a list of three items which contains Orange, Apple, and Banana.  

Now, look at the image below-  
append to a list  
The difference between add items to list and append to list is that for add items to list, you can add both individual items and lists, but for append to list, you can only add another list into a list. add items to list will consider a list as an item but append to list will take the contents from a list and add them as separate items. To make things clear, in the above image, list1 is the destination list where the contents of list2 will be added at the end of list1. That means, list1 will contain whatever items it had before plus the items from list2. Note that list2 will have no change in its contents. If things are not clear, try it for yourself and see how they behave.   Both add items to list and append to list add an item at the end of the list. What if we want to add an item in a certain position? That’s when we need insert list item block. insert list item is used when you want to add an item into a list in a certain position. Let’s say you want to add a new item “Grape” into list1 at position 1. This is how you will do it-  
insert into a list  
As you have noticed, insert list items takes 3 arguments – the list where the new item will be added, the index or position where the item should be added, and the new item that should be added. Since we wanted our new item “Grape” to be added at the beginning of the list, we specified 1 as the index/position. Now our list1 contains four items – Grape, Orange, Apple, and Banana. Note that Grape is the first item in list1 and everything else got moved down by 1 because of the insert operation. Before we inserted Grape, Orange was in the first position, but now Orange is in the second position.  
Tips: Always apply whatever you have recently learned. Don’t try to learn everything first and then apply.  
3. Display List Items
A fancy way to display list items would be using ListView component. Here’s a detail tutorial on ListView.
In the example below, we used a Label component named FirstListContents to display the contents of list1.  
Display list items  
for each item and for each number both can be used for iterating/looping through a list. Here we used for each item as we are not concern about the indexes/positions of an item. When we will sort a list, we will be using for each number instead as we’ll need the indexes of different items in the list for manipulation. You can still use for each item for sorting, but you must define some local or global variables to access the indexes.   for each item is pretty simple. You provide a list to loop through and there’s a local variable named “item” given to you that holds the value of an item. Note that you can change the name “item” to anything you like. Remember “item” is a local variable, you cannot use it outside the scope. In for each block, the scope is inside the do section of for each block.  
for each scope  
To give you an idea, let’s say you want to get the sum of all items in a list. This is how you would do it-  
Calculate sum of numbers in a list  
We have a list named numberList which contains three items – 20, 30, and 10. We wrote a procedure named CalculateSum that sums up the numbers in our list and then displays the sum. We declared a global variable named sum and initialized it to 0. Initializing means assigning a value the first time when you create a variable. Inside the procedure, we again set the value of sum to 0. You might think the initial value of sum was already 0 when we defined the sum variable outside CalculateSum procedure. Well, you may want to use the same procedure again and again. In that case, it’s safe to reinitialize a global variable unless the previous value of that global variable should be retained. We used for each item block to loop through each item in our numberList and added to the value of sum. The execution of the above procedure would look like this-  

sum = 0

sum = sum + value at position 1 of numberList (0 + 20 = 20)
(Now the value of sum is 20)

sum = sum + value at position 2 of numberList (20 + 30 = 50)
(Now the value of sum is 50)

sum = sum + value at position 3 of numberList (50 + 10 = 60)
(Now the value of sum is 60)

The final value of sum will be 60.   Let’s say you want to display a random item from a list. That’s how you would do it-  
pick a random item  
pick a random item” block gets a random item from a given list.  
4. Remove List Items  
To remove an item, all you need to know is the index/position of the item you want to remove. If you want to remove number 30 from numberList below, you’ll have to pass 2 as the index as you can see 30 is in position/index 2 in the numberList below.  
Remove an item from list  
In a real world application, you may have to validate if a certain index/position exists in a list before you actually try to remove an item. If you have already downloaded the application that I mentioned at the top of this tutorial, you should see how I validated a given index before I try to remove an item.   To remove everything from a list, simply set the value of the list variable to a make a list block without any item or just use create empty list block. In the image below, we removed all items from numberList by setting the value of numberList to create empty list block.  
Remove everything from a list  
5. Replace an Item  
To replace a list item, you need to provide with three arguments – the list where you want to replace an item, the index of an existing item in the list, and the new item you want to replace an existing item with.  
Replace an item in a list  
In the image above, initially we had three items 20, 30, and 10 in numberList. We used replace list item block to replace the item at index 1 which was 20 with a new item 100. Now our numberList contains 100, 30, and 10.  
6. Search for an Item  
Searching for an item can be a little tricky because sometimes you will need to know if a particular item exists in a list, if it does, then you might be interested in knowing where or in which position that item exists. If you have multiple occurrences of the same item in a list, you may also need to know all the positions where the item exists in the list.
Search for an item in a list
In the above image, you can see we are trying to search for the item 30 in numberList which contains three items 20, 30, and 10. Before we started searching, we used is in list? block to check if that item exists in numberList. Block index in list gives us the first occurrence of 30 in the list if it exists. If the item doesn’t exist, it gives us 0. Since numberList above contains 30 in the second position, index in list will give us 2.   As of now, we only searched for the first occurrence. What if our list contained 30 two times? How can we get all two positions? Well, we have to use for each block and loop through each item in the list, then compare if the item we are searching for is the same as the item currently in the loop; if equal we get and store the index for later use. We do this for all items in the list.  
Search for all occurrences in a list  
As you can see above, 30 appears twice in the numberList, in the second and in the fourth positions. As usual, we first check if 30 exists by using is in list block. If it does, we use a for each block and compare each item to see if the item is 30. If it is, we store it in a global variable named resultText by appending. In this case, the final value of resultText would be [2] [4] because 30 exists in 2nd and 4th positions.   The above numberList as the name implies, contains only numbers. What if we had alphanumeric/text items? In that case, we would need to use the compare texts block from text drawer. See below.  
Search all occurrences of an item is a list  
Our search above doesn’t ignore casing. Meaning “apple” is not the same as “Apple“. If you don’t care about casing and you want “apple” to be the same as “APPLE”, or “Apple”, simply convert both sides of comparison to uppercase or lowercase before you compare. Choose one, if you choose upcase then use it for both sides. You can find both upcase and downcase in the Text drawer. In the above example, if you didn’t want to care about casing, you would change the comparison to-  
Compare ignoring case  
If you have noticed both sides used upcase. All we are doing is that we are converting “Apple” in the left side to “APPLE” and also converting the item in the right side to have also all uppercase letters. So, if the item in the right side was “apple”, it will become “APPLE”. I used upcase, you can also use downcase as long as you use the same case for both sides in comparison.  
7. Sort a List  
Sorting of list is explained here.  
8. Shuffle a List  
 Shuffling of lists is explained here.

Download the source ListBlocks and explore.

Download also the source UniqueSpeedyBirds to see how shuffling works.



  1. When I go to create a list, and try to put multiple values into it, it limits it only to two values. How to I make it so I can have more than two values in a list?

    • If you click on the blue square in “make a list” block, you will see you can drag more slots.

  2. How do i get call ‘setup header’ the purple block

  3. hmm, I’ve tried to make a list of variables to try to make a math game as a project for school, but it just doesn’t work. Can you tell me how can I generate a number set for multiples of ex. 2,3,4,5,6 to a certain cap? (like from 1-500?) I would like to try to avoid writing an extremely long list. Thanks

    • Have a for loop starting from 1 until 500. For each iteration, do your math and store the result as an item in a list. You should do it after app loads.

  4. Can you a make lists from, for example, different fruits selected on different screens?

    • Multiple screens manipulation is not the scope of this tutorial. If you are having problem with that, you can actually have a tiny db and populate it with different items from different screens..then pick the contents of the db anywhere in your app.

  5. Hi,

    Does anyone know how to search for all numbers higher than 0 in a list and return the correct values? I cant seem to find the answer?

    • Loop through the list and do a “if”. If greater than 10, store it to another list to display later or append to a Label’s Text to display.

  6. Hello, I was wondering if anyone knows how I can share my data from my first list across multiple screens using a tinydb?

  7. Thanks Sajal for this very well-created primer on lists (I got here thanks to SteveJG pointing me here on the forum). As a rank beginner, it provided fantastic learning and set me off on to bigger things!

    Much appreciated,

  8. Hi Sajal. Thanks for this very informative article about Lists. It certainly clears up some issues i had. Can I email/private message you – i have a detailed query concerning lists and would like some input?


  9. Thankyou very much for your article, it’s amazing to know app inventor can do powerful like array ‘things’ and process it

  10. Hi i have made a search app to search from a standard make a list. But when my inputs in the list rich 694 and above when i try my app returns me: The second argument to foreach is not a list. The second argument is: *nothing*. when i delete one input and its back to 693 my app works perfectly. i am doing something wrong? thanx for your help!!!

    • If you are using ‘for’ block as I showed above, then ‘from’ should be 1, ‘to’ should be the length of the list, and ‘by’ should be also 1.

      • i use “for each (item) in list do” you say to use “for each (number) from” inside or outside “for each (utem) in list do” ?

    • I do not see anything wrong with your blocks. Should be fine. Does it happen if you change the 694th item to anything, like “apple”?

      • whene i give a new input to the list give me the problem. It is posible to sent you the .aia file to look the app?

        • Sent me a link where I can download your aia.

    • You have a lot of empty slots in your list. Remove those. These are causing problems I guess which you can report to AI2 issues. You can try keeping your empty slots and add more items at the end, and you will see it still works.

      • thanx for your time i wil try to add more empty slots ti see if start to work

  11. Please, how do I make the items in my list to be select able and open a new screen.

    • If you have downloaded the ListBlocks project that is provided at the end of the tutorial above, you should see the functionalities you are looking for under Sort function.

  12. Hi everyone

    I have just started to use app inventor and have been following the tutorial on lists.

    If I re-create all of the blocks on one screen will the demo work like on the screen shots? In other words does each function need the blocks on separate screens e.g. create list, add items to list etc…

    I have got to removing items from list and I cant create a block that says (number list) instead it says (number list4)

    Looking at the other blocks on the screen I can see I have used this a few times that’s why it automatically is numbering each one. Therefore does these blocks need to be on separate screens?

    Please help
    Thanking you all in advance.


  13. Just need to know how to:
    1 – click a button, that will each time it is clicked, show the item in a list. In this instance it needs to be iterating through the index of a series of numbers 1-10.

    2 – click another button to reset the list to the initial number, 10.
    3 – it should also preserve the number that is selected.
    4 – finally i should be able to do the same with five other lists.

    Hoping someone can help. Get lists, but don’t see how to do what I have just asked about. Cheers

  14. I want to make a list where i can ‘reserve’ and ‘cancel’ items, adding and removing, but i don’t know how.

    • This tutorial explains both adding and removing. Not sure what you are not understanding. For an inventory system, a list of available items with their quantity in the store and a list of items a customer has. Manipulate customer’s list. If they want to add, add to the customer list and subtract from available list..same goes for removal. Try to understand the tutorial above.

  15. I understand what you’re saying in your instructions. How can you set up a search for any text match in your app. For example, a user enters “Eric” in the search field. It should bring up any matching text, such as, Erickson, Erich, Deric. Do you create an empty list or what?it’s looking for numerous text values in a database, but you don’t know what they are at any given time, so you can’t add them like you do banana, apple, etc.

    • When your text box has focus, activate a timer. When timer/clock fires, check for a match in your existing list using whatever in the text box.

      • Hey Sajal, I am currently doing App Inventor for homework and do not know what to do. I have to make a computer booking system and wondered if you could assist me in doing it, it will be hugely appreciated,
        Ryan Woodcock

  16. How can you make a search bar in MIT App Inventor where you can search for someone else’s username which was stored when someone registers.

    • You would do that in your server, not in your app. Your app should send whatever a user chooses as their username to your server; your server verifies if that username is available, and send a response back to your app. From there, you handle accordingly.

      • Dear Mr Sajal

        You had make a great extra tutorial for us to start programming. My question is i would to upgrade portal and can do some simple search and display by using the app.

        My problem is how to do the searching withing the website source for the keyword and display the word following. I not sure how to do it as you mentioned to link to the server.
        Thanks for your time in advising me.

        • Not sure what you intend to do. Are you asking to use a WebViewer and do a serach inside the viewer? If it’s the case, you cannot because a viewer just displays and doesn’t and shouldn’t change the site’s content. I am sorry but I am not clear on what you are trying to do.

  17. How do you remove and add single items from a list

  18. I made an APP, with APP Inventor2, that sends SMS with latitude and longitude, but I can not make a schedule to send SMS for two, anything I try it sends to the first number I signed up. I have tested various possibilities, I made for each, and no longer know how else to solve..

    Can you help, please?

    Thank you.

    print of code used:

  19. My csv file contains 2 strings, Serial_Number,Ailment.(separated by comma(,).
    3,fever etc….

    I want to populate only the ailment names in the listview.

    Pl. help

  20. Hi,

    I have a csv file with three fields – separated by comma.
    part no , part desc, location
    K87,Nut, rack 2
    P34,Screw, Rack 3 and so on..

    At the start, I want to populate the part desc in a list view.
    on selection, display the location of the selected part in a textbox.
    Checked on lots of examples. these show creating data (static data). But in my case, it has to be read from a csv file.

    Pl help

    • Let me tell you what I have done so far.
      1. created two files part_no.csv and part_desc.csv. Both contains one field.
      2. Used File1 component for importing part_no.csv
      3. File Got Text event, populated listview1 with csv contents.
      4. Upon listview1 selection, got file2 component for part_desc.csv
      To do:
      Get listview1.selection match with that of the file2 and display the correct row.
      (let’s say screw is selected which is the fifth item in csv file1, the corresponding 5th entry in file2- rack 2 should be displayed in a textbox.

      Pl. help

  21. Is it possible to store imagesprites in a list?

  22. Hi!

    I have a certain number of list, let’s say 100. I would like to choose a specific list (e.g. list number 19), when an event is triggered.
    Therefore, when event19 is triggered, I need list 19 to be displayed. How can I do this?
    Do you have any idea?

    Of course, I cannot use if/else blocks, otherwise it would be too long and I should add more parts when I add other lists.

    Thank you!

    • Since App Inventor doesn’t provide a HashTable or the like, you may try using 2 separate lists. First list contains all the keys example Fruits, Vegetables,..etc. They should be unique. Then in the second list which would be a list of lists that contains all the lists that can be displayed. So, if first list’s item at index 1 is ‘Fruits’, then the first item of the second list is a list corresponding to fruits list. So when a user or event triggers Fruits, you check in the first list in which index Fruits is stored. Use that index to retrieve the list to be displayed from the second list.

      Another way would be much easier and that is use TinyDB. Since TinyDB uses a key-value pairing, you can use your trigger list keys as Tags in TinyDB and the actual list to display as the value under that the corresponding tag.

  23. How do you get a list to work across screens, Ive been trying for a school project but have had no success

    • You can use ‘open another screen with start value’ block when you open a new screen and pass the list you want the new screen to manipulate. You can take a look at the tutorial below on how to use that block. Also, you can store the list (or lists) in TinyDB with a specific tag (or tags for multiple lists) and access it across screens.

  24. How do I select four uniqe values from a list?
    I store this in an empty list but sometomes there are duplictaes in the list

    Thx in advance.

  25. Hola, tengo una lista de palabras,¿como puedo hacer que cada vez que se inicia la pantalla aparezca esa lista desordenada?,para que no aparezca siempre con el mismo orden, que los item de la lista ¿sean aleatorios?

    • How do you know that it didn’t work. After you remove, print the list to a label and see what it prints.

  26. I have a long text.
    My mom language and esperanto.
    I want my app to show separately in 2 Label, at the same index, my language and esperanto.

    Pliz Help.

  27. I cannot download the sourcecode, it only shows weird decription when clicking on it. Could you mail me the sourcecode please

    • Your browser setting is messed up! Try right clicking and then save link as or something similar to whatever browser you are using.

  28. hello.we have a project, basic quiz.. in an english word pool application will pick up a word randomly, and it will request the meaning of the word. when option selects correct answer, program will give a positive reply. when option selects wrong answer, it will give a negative reply. and options and correct answer will be generated randomly.

  29. I have a list of X Y coordinates i need to put in a list to Draw.Circle on the canvas

    I have 80 sets of X Y

    How do I populate them into a list?

    Do I just use the Make.list block and plug in all the X’s one at a time – and then do the same for the y”s?

    • There are just too many ways you can go about it. The easiest would be copy the whole set of x/y as a text in a text block. Then create a procedure to parse (using split function of Text block) the text and populate a list. You can treat each pair of items in the list at a time. e.g. first item in list (at index 1) will contain X, the 2nd item will contain Y. Index 79 will contain X, index 80 will have Y, etc.

      You can also use TinyDB.

      • ok – when Score text = 1 etc I need to call the XY to

        would that be easier to do with the TinyDB?

        • It would be almost the same. An advantage of using TinyDB over List is that you can use the same tiny db in different screens.

  30. I want to make a list from items in my list.txt file. how can i do that?

  31. how can i have 2 lists parallel each other, say if one stores names and the other stores telephone numbers? how would i be able to display the correct number for each name?

    • Just use the same index. If you put a store name in index 1, you put the phone number on the other list in the same index. Index is the key.

  32. hey. how does one retrieve say phone number from from screen 1 in screen 6 by using the persons name. in that screen 1 has the both the persons name and phone number, through a search button….thank you in advance

  33. i have created a list and added items to it.when i am using the list using a “pick a random item lis”t ,it is showing error while running.says “picking item from empty list”‘

  34. Hi Sajal gr8 jod this tutorial helped alot , I am trying to make location aware app of level crossings in Railways for that I have collected Lat and Long in seperate list I want to compare current GPS location wether it is in ring fence of preloaded lat long help me to compare current lat & long with list of preloaded lat long in seperated lists.

  35. Hi i new to MIT .Can we remove the entries from the tinywebdb??

  36. Where Do I Find The Procedures Block, ” To [SetupGameVisibility]
    In Your Oh My Spikes Game? Please Help Fast!

  37. Can you help me, i have 2 list (list question and list answer) in random mode, but when run question and answer not synchrone it. How to synchrone both of them?

    • You need to make sure you are maintaining the correct indices on both lists.

  38. Hello! How set label text from all items in list (not once) instead numbers (index) ?

    For example: List

    2 – a (index = 1)
    3 – b (index = 2)
    2 – c (index= 3)

    Where “thing” or “key” (lookup in pairs) = 2

    Label text=> a, c

  39. What is the maximum number of indexes in a list? ANSWER AS QUICK AS POSSIBLE, PLEASE!

  40. Mr. Dutta, this is a great tutorial. Is there a way to average all of the selected numbers against the total numbers in the list? Example, if there are 137 numbers in the list and the number 12 is in the list 14 times, can you get a result of the average times 12 was listed?

  41. Dear Mr. Dutta,

    My friend and me want to build an app, but we are stuck on a specific part.
    We have 3 spinners, each having 4 different options. We want to use this for the following:

    If a user selects an option from each of the 3 spinners, we want the outcome to be an answer in text.

    For example:

    Spinner 1 has the option Flour, Bread, Rice and Potatoes

    Spinner 2 has the option Egg, Chicken, Ham and Cheese

    Spinner 3 has the option Orange Juice, Water, Yoghurt and Milk

    Now if someone chooses Flour (spinner 1), Egg (spinner 2) and Milk (spinner 3) we would want the answer to be something along the lines of: You can use these ingredients to make pancakes.

    As we have 4 options in each of the spinner, there are 4x4x4 = 64 different possible answers. We already made all the different possible answers, we are just stuck on programming it..

    We were wondering how we could program it like this using MIT App Inventor 2.

  42. Great tutorial, thanks. Lists are more clear to me now. I need to import the data from a fusion table into a list. Could you point me towards a tutorial that covers this please.



  43. Hello
    Am unable to delete my list if put wrongly.

  44. Hi Mr. Dutta,

    Hi Everyone!

    I really don’t know how this block work like

    And please help me about my problem,
    Example I Have this Data.

    Store Name,Customer Name,Item Code,CS Qty,Price CS\n
    Lemacel Store,Jun Joseph Juare2149,2,1987.20

    In exporting to raw data it displays like this
    Store Name Customer Name Item Code CS Qty Price CS
    Lemacel Store Jun Joseph Juare 2149 2 1987.20

    But I want to preview only like this data in my Phone.
    preview at
    Item Code CS Qty Price CS
    2149 2 1987.20

    How to do that? Some blocks I don’t know how to use. Are there any blocks that can separate and preview only from the list just what I have an example above? Please help me for my thesis. Thank you in Advance!

Submit a Comment

Your email address will not be published. Required fields are marked *