2011-03-09 36 views
0

我要像做 Click <a href='www.google.com'>Here</a>的Android Linkify一個完全無關的字符串

在android系統

。我嘗試使用以下:

TextView sponsoredlink = new TextView(this); 
       sponsoredlink.setId(R.id.details_sponsored_link); 
       sponsoredlink.setText("Click Here"); 

       Pattern pattern =Pattern.compile("Here"); 

       String link = "www.google.com"; 

       Linkify.addLinks(sponsoredlink, pattern, link); 

,但我只是結束了一個鏈接www.google.comhere [原文]

回答

2

只是爲了回答我的問題,我發現變換濾鏡教程和適應這對我自己的目的:

TextView sponsoredlink = new TextView(this); 
       sponsoredlink.setId(R.id.details_sponsoredlink); 
       sponsoredlink.setText("Click Here"); 

       TransformFilter mentionFilter = new TransformFilter() { 
        public final String transformUrl(final Matcher match, String url) { 
         return new String("http://www.google.com"); 
        } 
       }; 

       // Match @mentions and capture just the username portion of the text. 
       Pattern pattern = Pattern.compile("."); 
       String scheme = ""; 
       Linkify.addLinks(sponsoredlink, pattern, scheme, null, mentionFilter); 

我決定,我希望把整個文本進入到最後一個大環,所以我做了匹配整個文本的模式。

然後我創建了一個變換過濾器會忽略你給它什麼,並返回我想帶人

該計劃還必須是空串,所以沒有東西在月底添加URL

最後我用linkify把它放在一起

相關問題