07-15-2008 04:25 AM
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?
Solved! Go to Solution.
07-15-2008 05:13 AM - edited 07-15-2008 05:14 AM
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;
}
}
07-15-2008 10:07 AM
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;
}
};
07-15-2008 10:38 AM
You can also use an ActiveAutoTextEditField and adjust the READONLY and FOCUSABLE properties as desired.
Tariq
07-15-2008 10:54 AM
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.
07-15-2008 01:35 PM
01-15-2010 07:19 AM
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.
01-15-2010 08:13 AM
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-Develo
02-08-2010 12:45 AM
Hi,
This information was a lot of worth and useful. Pleae tell us how can we make these clickable labels center alligned .
Thanks
03-29-2012 09:57 PM
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);