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

Java Development

Reply
New Contributor
soapmctavish
Posts: 9
Registered: ‎07-17-2012
My Device: Blackberry Torch
Accepted Solution

How to make LabelFields inline

I'm working in a Blackberry app (OS 5.0) and need to show recent tweets of the user.
I'm able to get the data from Twitter's end. Now after parsing the entities (hashtags, urls, user-mentions etc), I need to display them with separate formatting (color, bold etc). So I'm using different LabelFields for different parts of the tweet.
But LabelFields are by default block elements. How do I put those LabelFields inline, so that it looks like how it is shown in Twitter?

Like this:


Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to make LabelFields inline

Blackberry Fields are always rectangular, so to get the formal you want you will have to overlap the Fields, which starts getting a bit complicated.

 

Instead I would suggest you create a single Field, and then override the paint() method to paint the text that you want.  Then you can set the color and font, draw a bit of text, change the color, draw another bit of text, and so on.  Sounds really complicated, but it is actually easier than you might think. 

 

In this case however you might be better using a ListField, becuase you have rows.  Each row can be painted in much the same way, and ListField is very efficient if you have loads of tweets to show.

 

Also, have a look here

http://supportforums.blackberry.com/t5/Java-Development/Implement-advanced-buttons-fields-and-manage...

for some other useful UI components and sample code.

 

Good luck

New Contributor
soapmctavish
Posts: 9
Registered: ‎07-17-2012
My Device: Blackberry Torch

Re: How to make LabelFields inline

Ok I'll try this.

Any suggestion on how to handle urls? If there is any url in the tweet, I need to navigate the user to that url on touch/trackball click. So I need to make the urls focusable, and detect touchEvent on the urls, like the native Blackberry Twitter application does.

Thanks.

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to make LabelFields inline

Now that is a little complicated.

 

In which case you might like to consider using a RichTextField and not a ListField - then you get this for free.  have a look at this too:

 

http://supportforums.blackberry.com/t5/Java-Development/Format-text-in-a-RichTextField/ta-p/445038

Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: How to make LabelFields inline

In fact, there is a field which was made specifically for this purpose - ActiveRichTextField. You can even navigate between various "regions" of this field and have different click reactions in different parts.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to make LabelFields inline

Thanks arkadyz - I actually meant ActiveRichTextField, I don't think RichTextField has hot spots!

New Contributor
soapmctavish
Posts: 9
Registered: ‎07-17-2012
My Device: Blackberry Torch

Re: How to make LabelFields inline

Thanks a lot guys :smileyhappy: