Select Elements by using a String name / how to pass elements to a process

Hey there,

appinventor is driving me nuts. What I am trying to do is to simply select different elements based on their string name, but appinventor wont let me.

So there are 9 images, which can all be selected. I'd like to create a procedure, that changes their respective image when they are selected. Therefore I would need to pass the button to the procedure, example "butt_1" and change its image from "butt_1_image_1" to "butt_1_image_2" and vice versa.

Same for "butt_2", "butt_3" etc.

Also I would like to iterate through all buttons later on, to find out if they are selected and if so, to add a respective string to a list, that I pass on to another screen with TinyDB. In python I would simply merge two strings and call the variable "butt_" + "number" an incrementing while list. But in appinventor I cannot do this apparently, I can only directly select the variable through the get method, but not through using a merged String in the get method.

There must be some solution for this no? It is very basic

c functionalities, however, I could really not find any :confused:

Thanks for your help :slight_smile:


Well try this code.
Button_and_Image.aia (3.7 KB)

I have not added pictures to it, but follow this naming convention -


1 Like


thanks for the quick reply & help :slight_smile: this forum is always great! While it has some nice ideas in there, it does not completly solve the problem of repetitive code / copy pasting it.

What I would like to have removed as well is this whole part:

I do not want to have one block for every image. Instead something like the button number, which was passed as an argument to the method, to merge with "image" --> "image1", "image2" etc., so that it is automatically selected and just needs one block.

now it needs one block of repetitive code for every Image, which is rather bothersome and ugly :wink:

It might save me a bit of code in this way and it gives me some nice new ideas, but it wont save too much I fear.

Thanks in any case!


Do you want to be able to change the image for each button to any of the 9 images or just the next one?

For every button there exist two images, the second one of which is the same image with a dark-blue overlay, so that the user can see that he has selected it. Pressing the button once shows the blue image, pressing it again reverses back to the normal image.

The boolean values / wether an image was selected for training will need to be passed on to the next screen when I press "Start exercise" - but this I can solve with a list and a TinyDB. But again, I will need to copy paste a block for every single button to check if it is selected or not :sleeping:

The Shortened code -
Button_and_Image(1).aia (3.2 KB)

1 Like

Good to know!! :smile:

Please that do that, it will helpful

Ah sweet, that is exactly the block that I needed!!! Didnt know that it exists. Thank you so much !!
For anyone searching for this later on:

There are general blocks for all the elements that you use to be found on the left.

1 Like

The generic blocks get more useful if you keep lists of components for the purpose of addressing them by index. Sample app ...

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.