The scenario is that if, for example, there are 5 vertical arrangements on the screen then 4 should be hidden and only one should be displayed. This is a useful thing to be able to do, especially for navigating between several pages on a single screen.
In this demo app there are seven labels, one for every colour of the rainbow. There is a toggle button at the bottom of the screen and a textbox which allows the user to specify which label they want to display.
Start by creating a list of all the labels:
For this app I also created a list of colours, but your app could just as easily have a list of text values, background images etc.
With these two lists it is possible to give each label a unique colour using the “for each item in list” block. You can find this block in the “Control” category.
Using the “for each item in list” block again, we can create a procedure to show all the labels and hide all the lables. Creating the “showAllLabels” variable allows us to do this reliably.
Finally, we can display one specific label with the following blocks:
First we check to see if the user has entered a valid number, then, if they have we hide all the labels and finally display the specific label that the user has requested.
If you want to try this code out for yourself here’s the .aia file.
lists_of_components.aia (3.7 KB)