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
Posts: 7
Registered: ‎04-08-2010
My Device: bold
Accepted Solution

need hyperlink code....

please can anybody help me to make a simple hyperlink in blackberry application?

i just want to make a simple hyperlink code from one page to another page..

 

sorry if my English language is bad.. Smiley Tongue

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

Re: need hyperlink code....

Welcome.  Smiley Happy

 

Your English is great!  Better than my Java probably. 

 

There are a number of ways this could be achieved.  The easiest way to do it is to put a button on you page and create a FieldChangeListener for the Button, and when the button gets pressed, pushScreen the screen you wish that Button to link to.

 

I suspect however that you have other requirements that this solution will not address, such as the link appearing 'in line'. 

 

If you look at some of the samples around, that will tell you how to implement a Button and how to pushScreen from on page to another.  Once you have understood that, perhaps you can review your requirements. 

New Contributor
Posts: 7
Registered: ‎04-08-2010
My Device: bold

Re: need hyperlink code....

thanks peter for your information. it's help me.

now i understand to make a hyperlink with a button.

 

hmm.. how about if i want to make some word into hyperlink?

 

can you give me an example code to make that? Smiley Happy

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

Re: need hyperlink code....

Search the forum, that question has already been asked and answered.  Smiley Very Happy

New Contributor
Posts: 7
Registered: ‎04-08-2010
My Device: bold

Re: need hyperlink code....

[ Edited ]

i got this code, but when i try, why it didn't work? can you help me?

 

package sample;

import net.rim.device.api.ui.Manager;

import net.rim.device.api.ui.component.RichTextField;

import net.rim.device.api.ui.container.MainScreen;

 

public class SampleScreen extends MainScreen {

public SampleScreen(int screenNumber) {

super(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR); this.add(new RichTextField( screenNumber));

int nextScreenNumber = screenNumber++; this.add(new SampleOpenScreenHyperLinkField("Screen " + screenNumber, nextScreenNumber));

}

}

 

package sample;

 

import net.rim.device.api.ui.ContextMenu;

import net.rim.device.api.ui.Font;

import net.rim.device.api.ui.FontFamily;

import net.rim.device.api.ui.MenuItem;

import net.rim.device.api.ui.UiApplication;

import net.rim.device.api.ui.component.LabelField;

public class SampleOpenScreenHyperLinkField extends LabelField{

private int pageCount = -1;

private MenuItem mGetLinkMenuItem;

 

  public SampleOpenScreenHyperLinkField(String hyperlinkLabel, int pageCount) { super(hyperlinkLabel, FOCUSABLE); this.pageCount = pageCount; Font font = getBasefontSize(10); setFont(font.derive(Font.UNDERLINED)); mGetLinkMenuItem = new SampleOpenScreenMenuItem(hyperlinkLabel); } public ContextMenu getContextMenu() {

 ContextMenu menu = super.getContextMenu(); menu.addItem(mGetLinkMenuItem);

return menu;

}

 

class SampleOpenScreenMenuItem extends MenuItem {

public SampleOpenScreenMenuItem(String menuLabel) {

super(menuLabel, 0, 100);

}

public void run() {

UiApplication.getUiApplication().pushScreen(new SampleScreen(pageCount));

}

}

public static Font getBasefontSize(int size) {

Font baseFont = null; try { baseFont = FontFamily.forName("BBClarity").getFont(FontFamily.SCALABLE_FONT, size);

} catch (ClassNotFoundException e) {

baseFont = Font.getDefault().getFontFamily().getFont(FontFamily.SCALABLE_FONT, size);

}

return baseFont;

}

}

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

Re: need hyperlink code....

The code looks like it should open a menu item when you click on the link, the user can choose the menu item to link.  Is that what you see?

New Contributor
Posts: 7
Registered: ‎04-08-2010
My Device: bold

Re: need hyperlink code....

wow.... i understand now..

thanks peter..  Smiley Very Happy

New Contributor
Posts: 3
Registered: ‎05-13-2010
My Device: Storm 9530
My Carrier: Blackberry Developer

Re: need hyperlink code....

[ Edited ]

 

Hope this will help....Smiley Happy

 

HrefField hlink = new HrefField("Your Link"){

 protected boolean navigationClick(int status, int time) {

 System.out.println("clicked");

         return true;  

  }

};

 

 

 

import net.rim.device.api.ui.Font;

import net.rim.device.api.ui.Ui;

import net.rim.device.api.ui.component.LabelField;


public class HrefField extends LabelField {

public HrefField(String hyperlinkLabel) { 

super(hyperlinkLabel, FOCUSABLE); Font font = defaultFont(); setFont(font.derive(Font.UNDERLINED)); 

}  

 

protected boolean navigationClick(int status, int time) {

fieldChangeNotify(1);

return true; 

}  

 

public static Font defaultFont() { 

return Font.getDefault().derive(Font.PLAIN,6,Ui.UNITS_pt);

}

 

}

 

Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: need hyperlink code....

The code really helps me a lot...Thanks

Im new to BB can you guide me for developing applications??

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

Re: need hyperlink code....

Start here:

http://developer.blackberry.com/

 

You will see a link to Java if you search round there you will find loads of useful information.

 

Good luck and have fun!