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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
Berrysoft
Posts: 143
Registered: ‎07-14-2008
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?

 

Please use plain text.
Developer
jhfisher
Posts: 16
Registered: ‎07-14-2008

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
Please use plain text.
Developer
peter_strange
Posts: 17,631
Registered: ‎07-14-2008

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;
    }
};

 

Please use plain text.
BlackBerry Development Advisor
ttahir
Posts: 36
Registered: ‎07-14-2008

Re: Make an email label clickable?

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

 

Tariq

Please use plain text.
Developer
Berrysoft
Posts: 143
Registered: ‎07-14-2008

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.

 

Please use plain text.
Administrator
MSohm
Posts: 12,957
Registered: ‎07-09-2008
My Carrier: Bell

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.
Found a bug? Report it using the Issue Tracker
Please use plain text.
New Developer
AbdurRahim
Posts: 32
Registered: ‎11-02-2009

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.

Please use plain text.
Developer
peter_strange
Posts: 17,631
Registered: ‎07-14-2008

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

Please use plain text.
New Developer
aman_105
Posts: 1
Registered: ‎02-08-2010
My Carrier: Vodafone

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

 

Please use plain text.
New Developer
manarS
Posts: 34
Registered: ‎03-12-2012
My Carrier: zain telecommunication compay

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);

 

Please use plain text.