Reading fields from a csv file

Hello all. I'm a newbie.

I have a csv file. The fields are delimited with ; (semicolon). It looks like this

Boat;Boat on the river;boat.jpg
Car;Sportscar in the mountains;car.jpg
Lake;Sunset over the lake;lake.jpg

I managed to read my csv. I can display the whole rows. However I cannot figure how to address the individual fields of each row. Can I iterate through these or do I need to apply a splitting looking for the ;?

So e.g. I want to show on my mobile the Title, I want to load the picture based on the jpg-name and below that I want to display the description.

How do I need to extend this textblock, to read e.g. only the jpg name into a variable that I can use later on for loading the picture?textblock


Something like this should work on your csv file to return a list of lists to your app.
It relies on there being NO commas , in any of your fields, because the semi-colon ; is replaced to make a correct csv formatted file for AI2 to work with.

Thanks for your help. What I still don't understand is, how do I specificially address one field from the row? How can I get the "Description" from my row into a new variable, that I will then show alone?
I would expect something like for each item in row, do ...

Do you want to display all your data in a table?
How do you want to interact with the data, e.g. selecting

As mentioned in the end I want to read the rows from my CSV-File. I then want to show on a screen the Title, I want to load a stored picture based on the picture name and in one area I want to display the Description.
I have some randomize process that will triggered by a button and each time read from the list/file and show the content accordingly.

On load picture of boat, title and description.
On button click (other event) show next picture and text.

Yes ?

Yes. That would be the intention.

Here is a simple example. Assumes your images are in your assets.

1 Like

Thanks for the picture. This helped massively! !!. I was able to do a similar construct in my block. I have added some randomization.

1 Like

Good morning.
In my app I read a csv textfile with 80 lines in this format
Title,picture-name.png,descriptions about the picture
I read the lines in random order when a button is clicked.
I tested this with the companion. Everything worked fine.
When I created my first apk and installed it on the tablet, I found that the images are not loading or not showing. I cannot figure out what the issue is.
I have 80 images with a size of around 40 kb each. The image size in my app is defined with 300 x 300 pixels. I have also changed the size of my images to 300 x 300 pixels. I have assumed that I need to upload all images into the App Inventor and create then the APK. Questions:

  1. What could be the issue?

  2. I need this app only on one tablet. Is it an option to create the APK without the images I load via my csv file and instead place them directly in the app directory? If this is possible, how do I need to reference the path in my app? In the companion mode I had just // and all files where under the android companion files directory


Got it resolved. Just had to remove the // and everything is ok.
Maybe still the question: If I don't want to have the pictures as part of the APK and rather store them locally under the application folder. How do I need to reference them in my blocks so that the app finds them?

1 Like

You should be able to copy all your images to the /storage/emulated/0/Pictures folder on the device.

Then you use /Pictures as your folder
You may need to request READ_EXTERNAL_STORAGE permission for your compiled app

This works for me with mp3 files in the /Music folder

How, from your PC to the device or should they be downloaded to the device first?
If these are created by the app itself, no READ permission is required for Shared folders (like /Pictures).

See also here:

Btw, what do you mean by "application folder" ?