Showing results for 
Search instead for 
Did you mean: 

Getting data from List Layout Elements

Associate II

I am not very experienced with CPP or TouchGFX. I have created a Custom Container with a TextArea, a ToggleButton, and a couple of ScrollWheels. I have created a list layout, and used .add() to add two new instances of the Custom Container to my list at run time. The purpose is to create a list of alarms with a title, and some settable parameters for the User to set and save. I have figured out how to load the saved values into the ToggleButton and ScrollWheels from the values saved in the Model in setupScreen.



listLayoutAlarmList.setWidthHeight(0,0); //Compensates for the list height that is set to 200 by the designer


for(int i=0;i<2;i++)


CustomContainerAlarm *ac = new CustomContainerAlarm();

ac->setListElements(i, (int)!presenter->getAlarmEnable(i), presenter->getAlarmPriority(i), presenter->getLimitF(i), presenter->getAlarmRelay(i));





But now I need to save the current settings from each alarm (Custom Container) back to the Model during tearDownScreen.

I thought I could get the first Child of the ListLayout, and step through to the last Child by incrementing the pointer. But getFirstChild returns a Drawable *. How do I use this to get the TextArea (so I can tell which alarm I have) from inside the CustomContainer it must be pointing to, then each of the other elements in the CustomContainer so I can for example save whether the ToggleButton is on or off.

Then how do I move to the next list layout element, and how do I tell when I am at the end?


Accepted Solutions

Brilliant thanks.

View solution in original post

ST Employee

Hello @CYBR,

When you add code to your post, please format your code for better readability by clicking on this icon: 



You can scroll through your list by calling the first item with listLayout1.getFirstChild(). Then you need to use a while loop while the nextSibling is not NULL( = end of the childs list).

Inside the while loop, to access to your container data/function, you will need to cast your current element to your CustomContainer.



    Drawable * next = (listLayout1.getFirstChild());
    TypedText* containerText;
    CustomContainer* current;
    while (next != NULL)
        current = (CustomContainer*) next;
        containerText = current->getTextArea();
        next = next->getNextSibling();




To get the customContainer's text area content, you will need to add a new function to your custom container:


    const TypedText& getTextArea() const{
        return textArea1.getTypedText();


with textArea1 the name of your text area.


I hope it helps,


ST Software Developer | TouchGFX

Brilliant thanks.