Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
Posts: 19
Registered: ‎06-26-2013
My Device: BlackBerry Z10
My Carrier: It's a test device without a SIM
Accepted Solution

Programmatically setting text of labels.

[ Edited ]

I am working on a project that requires lots of labels and text fields (lets say more than 100). I would like to:

  • get/set the text of a label
  • get/set the text of a textfield

I can do this manually, however is there a way to do this programmatically (i.e. run it through a loop), preferably in QML over C++. Any help will be appreciated.

Developer
Posts: 16,986
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Programmatically setting text of labels.

if all these labels are in a container you can use its methods like count, at etc to iterate over fields in them.
if there are other fields you are not interested in you could, for example, set a custom property on the fields you are interested in and check for that.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

Re: Programmatically setting text of labels.

You could use javascript loops...

Contributor
Posts: 19
Registered: ‎06-26-2013
My Device: BlackBerry Z10
My Carrier: It's a test device without a SIM

Re: Programmatically setting text of labels.

The problem with count() is that there are multiple levels of containers in my qml. And it'd almost be just as difficult to iterate through it. I was looking for something that'd let me set numeric the ids of the text property. Is this possible?
Developer
Posts: 16,986
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Programmatically setting text of labels.

you could add the textfields to a data structure (in addition to the container) and iterate through that.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
Posts: 19
Registered: ‎06-26-2013
My Device: BlackBerry Z10
My Carrier: It's a test device without a SIM

Re: Programmatically setting text of labels.

I'll look more into this, thanks for starting me off. Smiley Happy
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Programmatically setting text of labels.

Hi,

Another option is setting objectNames to follow a particular pattern and iterating item.children, matching objectName to this pattern. If there are multiple levels of containers, they can be processed by calling the same function recursively.

 

Please also check this thread, it has sample code for different methods of finding child items:

http://supportforums.blackberry.com/t5/Cascades-Development/getElementById-in-qml/m-p/2377935/highli...

 


Andrey Fidrya, @zmeyc on twitter