ListView CreateElement method use

What is the intended use of the new createelement capability of listview? The method signature, CreateElement( mainText , detailText , imageName ), seems to be intended to return something (a dictionary) that might be useful for building a listview with images. However, the listview listdata attribute is not available to use in code.

What is an example of something CreateElement could be used for?

1 Like

That's what I thought it was for too.

If so, I cannot tell how to use it. I took a wild guess and stuck the dictionaries in a list and set listview elements to the list of dictionaries, hoping that some parameter magic would interpret the dictionaries in the list as source for text and detail and image. No such luck. Maybe this is just a placeholder method for later.

1 Like

There might be enough information below to help find your way. :slight_smile: This is one of many ways you can use the tool.

You must set the ListViewLayout in the Designer. There are no Blocks for it.


:eye::lips::eye: I didn't understand the use of lists in the code, could you please elaborate?
Edit: nvm I got it



If you right click and Do It on a .CreateElement block when running companion, you will see how it constructs a dictionary. You can, as I have shown, just add this as a list item to a list.


Thanks for the help. I may have been on the right track.

In my case, the images are being captured as part of the app, so they will be coming from local storage, along the lines of



I'll try it out

1 Like

BTW, it is a nice job it reads in the dictionary and just works. I was hoping. I am guess I have something wrong elsewhere.

1 Like

Worked perfectly as advertised. I think since I was pulling the image from storage that I needed a full path definition (including the file: protocol).

The image files are taken from the /Pictures/ directory in the Apps file scope. The file name must be fully expanded for the image reference to work.

Note that if you want to delete the file, then you want to reference /Pictures/[filename]. So for example, image picture file name for the ListView CreateElement is file:///storage/emulated/0/Android/data/appinventor.ai_freddiegarvin.GeologyFieldTrip/files/Pictures/app_inventor_1630924067627.jpg

A call to file.delete needs /Pictures/app_inventor_1630924067627.jpg

Thanks everyone for your help.

1 Like

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