Struggling with a FOR NEXT loop type of situation

Hi. I'm working on a project that receives data from a database. In this particular case the data is a number. Depending on the number (could be anywhere from 1 to 20+), I need to do something such as making an arrangement (or label, or text box, etc) visible or not visible (along with other things also such as populating labels), but I'm keeping it simple for this request for help.

It's my understanding I can't create things such as arrangements, labels, text boxes, etc on the fly? Which leads me to creating up to 20+ arrangements with the necessary labels, etc inside them and turn on or off visibility, which I'm ok with if that is the only way to do it.

So, looking at my example blocks, if the number is a "3" I would need to make the first 3 arrangement visible and then do something with the contents of the arrangements. Doing it like in my example blocks could lead to an extremely large group of blocks.

I'm struggling with how to take the number I receive from the database and do what I need to do in the easiest way possible. In another basic language I use, I could use a FOR NEXT loop and do something like:

For i = 1 to count   ' "count" is from db
  VerticalArrangement[i].Visible = "true"
  (then do some other stuff also)
Next i

How can I do something like that in AppInventor? Because I'm totally lost on this one, I'm not even sure what I need to search for to find an example.

Thanks in advance for any help you can give me.

blocks

1 Like

image

1 Like

Thank you eAcademy for the example. I had looked at that FOR EACH block thinking it was a good possibility, but couldn't wrap my head around how to step through each Arrangement. Seeing the block creating a variable containing all the Arrangements was the key for me understanding how to make the FOR EACH block work. It certainly has a smaller foot print than what I was originally looking at. :slight_smile:

I will play with your example tomorrow to see how well I can build what I need.

Thank you again for your help!.

1 Like

You can display multiple data in a ListView using YAML.

Sample:

1 Like

I've spent some time working on my project using some modifications to your example. I think it will do quite nicely for my needs. Currently, I'm working on pulling data in from my SQLite db to populate whats needed inside each Arrangement that's needed to be visible.

1 Like

Thanks ABG for your reply. I've read through your link. Although I'm using an SQLite db for my project, I am using a few ListViews in other parts of the project and might be able to incorporate some of what's in that thread to tidy up my ListViews.

That's great to hear that It's working for your needs, yes please carry on. :+1:

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