Skip to main content
Associate II
July 29, 2024
Solved

TouchGFX 4.24 and textfield in container

  • July 29, 2024
  • 3 replies
  • 1191 views

HI, could you come up with an example of how to access a textfield from a custom container in the Main screen?

Thanks in advance.

    This topic has been closed for replies.
    Best answer by tdecker2

    If you have 5 instances of your CustomContainer on your View, you can give every instance a different text:

    myContainer1.getTextArea.setTypedText(touchgfx::TypedText(T_TEXT1));
    myContainer2.getTextArea.setTypedText(touchgfx::TypedText(T_TEXT2));
    myContainer3.getTextArea.setTypedText(touchgfx::TypedText(T_TEXT3));
    myContainer4.getTextArea.setTypedText(touchgfx::TypedText(T_TEXT4));
    myContainer5.getTextArea.setTypedText(touchgfx::TypedText(T_TEXT5));

     

    3 replies

    tdecker2
    Associate II
    July 29, 2024

    You have to add a public method to your CustomContainer-class, for example

     

    void setText(Unicode::Unichar * text);

    And copy the text to your textfield wildcard array. Then you can call this method from your Main screen view class.

    Another way could be exposing the TextArea object to the outside world by adding a method like this:

    TextArea & getTextArea() { return myTextArea;}

     

     

    amigafanAuthor
    Associate II
    July 29, 2024

    HI, thanks for the quick replay, but a have 5 identical containers in Mainscreen and then the textfields will have the same ID, and I want to access them individually.

    tdecker2
    tdecker2Best answer
    Associate II
    July 29, 2024

    If you have 5 instances of your CustomContainer on your View, you can give every instance a different text:

    myContainer1.getTextArea.setTypedText(touchgfx::TypedText(T_TEXT1));
    myContainer2.getTextArea.setTypedText(touchgfx::TypedText(T_TEXT2));
    myContainer3.getTextArea.setTypedText(touchgfx::TypedText(T_TEXT3));
    myContainer4.getTextArea.setTypedText(touchgfx::TypedText(T_TEXT4));
    myContainer5.getTextArea.setTypedText(touchgfx::TypedText(T_TEXT5));