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
Developer
Berrysoft
Posts: 143
Registered: ‎07-14-2008
My Device: Not Specified
Accepted Solution

Make an email label clickable?

I saw a post on this somewhere, and I'm probably going to kick myself, but for the life of me I can't find the post, or remember how to do this.

 

Basically, I want to make a LabelField which contains an email or web URL, clickable.  Anyone point me to something?

 

Developer
jhfisher
Posts: 16
Registered: ‎07-14-2008
My Device: 8310

Re: Make an email label clickable?

[ Edited ]

you could override some methods of a label field but i prefer to use this: href field

 

 

 

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.Graphics;

public class HrefField extends Field {

private String content;
private Font fieldFont;
private int fieldWidth;
private int fieldHeight;
private boolean active = false;
private int backgroundColour = 0xffffff;
private int textColour = 0x333333;
private int maskColour = 0xBBBBBB;

public HrefField(String content) {
super(Field.FOCUSABLE);
this.content = content;
fieldFont = defaultFont();
fieldWidth = fieldFont.getAdvance(content)+2;
fieldHeight = fieldFont.getHeight() + 3;
}

public void setColours(int backgroundColour, int textColour, int maskColour) {
this.backgroundColour = backgroundColour;
this.textColour = textColour;
this.maskColour = maskColour;
invalidate();
}

public void setBackgroundColour(int backgroundColour){
this.backgroundColour = backgroundColour;
invalidate();
}

public void setTextColour(int textColour){
this.textColour = textColour;
invalidate();
}

public void setMaskColour(int maskColour){
this.maskColour = maskColour;
invalidate();
}

public void setFont(Font fieldFont){
this.fieldFont = fieldFont;
}

public int getPreferredWidth() {
return fieldWidth;
}

public int getPreferredHeight() {
return fieldHeight;
}

protected void layout(int arg0, int arg1) {
setExtent(getPreferredWidth(), getPreferredHeight());
}

protected void paint(Graphics graphics) {

if (active) {
graphics.setColor(maskColour);
graphics.fillRect(0, 0, fieldWidth, fieldHeight);
} else {
graphics.setColor(backgroundColour);
graphics.fillRect(0, 0, fieldWidth, fieldHeight);
}

graphics.setColor(textColour);
graphics.setFont(fieldFont);
graphics.drawText(content, 1, 1);
graphics.drawLine(1, fieldHeight-2, fieldWidth-2, fieldHeight-2);
}

protected boolean navigationClick(int status, int time) {
fieldChangeNotify(1);
return true;
}

protected void onFocus(int direction) {
active = true;
invalidate();
}

protected void onUnfocus() {
active = false;
invalidate();
}

public static Font defaultFont() {
try {
FontFamily theFam = FontFamily.forName("SYSTEM");
return theFam.getFont(net.rim.device.api.ui.Font.PLAIN, 14);
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
return null;
}
}

 

 

 

Message Edited by jhfisher on 07-15-2008 05:14 AM
Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: Make an email label clickable?

Just for completeness, can I add the following?

LabelField _testLink = new LabelField("Test", Field.FOCUSABLE | Field.USE_ALL_WIDTH) {
    protected boolean navigationClick(int status, int time) {
        System.out.println("Linked");
        return true;
    }
};

 

Retired
ttahir
Posts: 36
Registered: ‎07-14-2008
My Device: Not Specified

Re: Make an email label clickable?

You can also use an ActiveAutoTextEditField and adjust the READONLY and FOCUSABLE properties as desired.

 

Tariq

Developer
Berrysoft
Posts: 143
Registered: ‎07-14-2008
My Device: Not Specified

Re: Make an email label clickable?

Actually, when I say "clickable", what I mean is not just that it is focable, but that when you click an email, it will invoke a compose of an email message, or when you click a URL, it will invoke the browser.

 

BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Make an email label clickable?

In that case you could use an ActiveAutoTextEditField (as Tariq mentioned bove).
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
AbdurRahim
Posts: 32
Registered: ‎11-02-2009
My Device: Not Specified

Re: Make an email label clickable?

Hi Friends,

 

I have text like this. in FAQs

 

Restaurants and local retailers coast-to-coast........

 

and I want like this:

 

Restaurants and local retailers Click Here coast-to-coast........

 

I try

but not work for me.

 

i ry it like this,

 

add(labelText1);

add(linkLabel);

add(labelText2);

 

then i try like this.

 

add(labelText1 + linkLabel + labelText2);

 

any other the Href class.

 

and i dont want to do by ActiveRichTextField

Please help me.

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

Re: Make an email label clickable?

I recommend that you do not add new questions to existing Threads, especially if the Tread has been solved.  Start a new Thread, which I see you have done here:

http://supportforums.blackberry.com/t5/Java-Development/Link-between-text/m-p/417331

New Developer
aman_105
Posts: 1
Registered: ‎02-08-2010
My Device: Blackberry perl 8330

Re: Make an email label clickable?

Hi,

 

This information was a lot of worth and useful. Pleae tell us how can we make these clickable labels center alligned .

 

Thanks

 

New Developer
manarS
Posts: 34
Registered: ‎03-12-2012
My Device: blackberry tourch

Re: Make an email label clickable?

Tariq, i did what you recommended..

but it doesn't work . it displays just like any label field, no different.

hyperlink=new ActiveAutoTextEditField("mnr.mars.87@gmail.com", " ", 30, Field.FOCUSABLE | Field.READONLY);