2010-08-07 93 views
1

谁能告诉我如何在Blackberry中创建一个URL链接,它在被点击后打开一个网页?如何在黑莓程序中创建一个URL

+3

什么了你试试?你有什么问题? – Oded 2010-08-07 08:11:36

+0

我是黑莓新手,我正在寻找显示url链接的代码,它应该在点击它后打开网页..我尝试了一些代码,但它不起作用... – user413715 2010-08-07 08:20:41

+1

再次:什么代码你试过了,它究竟是如何失败的? – 2010-08-07 17:05:00

回答

1
// This can eb a nested class in your screen class. 
class URLButtonField extends ButtonField { 
    String url; 
    public URLButtonField(String label, String url) { 
     super(label); 
     this.url = url; 
    } 
    public String getURL() { 
     return url; 
    } 
    public void setURL(String url) { 
     this.url = url; 
    } 
}  



// member variable of your screen class- this will let you access it later 
// to change the URL 
URLButtonField bf; 

// In your screen's constructor: 

bf = new ButtonField("Example", "http://www.example.com"); 
bf.setFieldChangeListener(new FieldChangeListener() { 
    void fieldChanged(Field field, int context) { 
     if (field == this) { 
      BrowserSession session =- Browser.getDefaultSession(); 
      session.displayPage(getURL()); 
     } 
    } 
});   
add(bf); 

然后,您可以更改“BF”的文字或目的地网址在任何时候,不管你把它改为将是启动被点击时,它的网址:

// In response to some activity: 
bf.setText("Example Two"); 
bf.setURL("http://www.example.com/two");