2024-07-29 04:38 AM
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.
Solved! Go to Solution.
2024-07-29 07:00 AM
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));
2024-07-29 05:27 AM - edited 2024-07-29 05:29 AM
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;}
2024-07-29 06:52 AM
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.
2024-07-29 07:00 AM
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));