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
Developer
sgallego84
Posts: 89
Registered: ‎10-18-2012
My Device: BB Z10
Accepted Solution

Set HTML text to a Label

Is there any way to assign HTML text to a Label so the text is correctly formatted?

 

 

Something like in Android:

textview.setText(Html.fromHtml("<p>Some text<br> Some text</p>"));

 

Regards

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Set HTML text to a Label

Try using the search feature of this board with something like "label html" and you should find answers. In short, wrap it with <html> </html> tags and it should work, though the support appears limited for now.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
sgallego84
Posts: 89
Registered: ‎10-18-2012
My Device: BB Z10

Re: Set HTML text to a Label

It works fine for me! Thanks!

 

Extending the question... is there any way to make <a href=""> links clickable and open the URL in the browser when clicked???

 

Thanks again!

 

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Set HTML text to a Label

There's supposed to be support for something like that, called Active Text. (Look for that phrase in https://developer.blackberry.com/cascades/download/releasenotes/ for example.)

Unfortunately there are no samples of how this is meant to work, nor documentation on it aside from that comment in the release notes, as far as I can tell. Possibly it's not really ready for us until the next release (in November?).

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
sgallego84
Posts: 89
Registered: ‎10-18-2012
My Device: BB Z10

Re: Set HTML text to a Label

We will be waiting for the next release.

 

Regards!

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Set HTML text to a Label

[ Edited ]

Actually, it sounds like it is supposed to work already!

 

I haven't tested this out myself yet, but @BlackBerryDev replied to my question about this on Twitter yesterday: https://twitter.com/BlackBerryDev/status/261211118243037185

 

 Have you had a look at the active text samples here: ? And checked your TextContentFlag?


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
sgallego84
Posts: 89
Registered: ‎10-18-2012
My Device: BB Z10

Re: Set HTML text to a Label

Its work already!!

 

You have to add the needed flag:

 

content.flags: TextContentFlag.ActiveText;

 

With this flag active, a long press over a link open a context menu con share and open options.

 

Thanks a lot!

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Set HTML text to a Label

I guess it sort of works....  I can long-press and it shows a pre-defined context menu with "Share" and "Open in..." options, and both of those do the right thing (at least, I can share with BBM, for example, and open in the browser).

 

If I merely tap on the URL, I get this in my log if I provide an onTriggered handler with the same QML code they have in the example in the docs.

11:41:14.116 ca.engenuity.QmlStudies qt-msg 0  QMetaProperty::read: Unable to handle unregistered datatype 'bb::cascades::ActiveTextTriggeredEvent*' for property 'QDeclarativeBoundSignalParameters::event'

Maybe this would work only in C++ for now?


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.