0

以下代码不起作用 -

   TextView myLocation = new TextView(this);
   myLocation.setText("Sodala, Jaipur, Rajasthan, IN");
   Linkify.addLinks(myLocation , Linkify.MAP_ADDRESSES);
   mainLayout.addView(myLocation);
4

3 回答 3

2

看来您的地址对于 Linkify 来说太模糊了。我不知道印度的地址是什么样的(如果它们完全不同的话),所以考虑一下美国的纽约:

myLocation.setText("New York, NY   34 Maint St New York, NY");

仅“纽约,纽约”不是 Linkify 的有效地图地址。

您可以尝试设置自己的模式,按照此处的示例来匹配任何带有“,IN”的内容。

于 2012-06-23T19:29:08.940 回答
1

这是带有自定义模式的addLinks的简化版本:

Pattern pattern = Pattern.compile(".*", Pattern.DOTALL);
addressTextView.setText(address);
Linkify.addLinks(addressTextView, pattern, "geo:0,0?q=");

我将它用于德国和美国地址,因为 google-maps 在搜索其他地方也应该可以找到的地址时非常聪明。

这个亮点是适合我用例的TextView的所有内容。如果地址位于字符串内部的某个位置,则需要在此处应用更智能的模式。

于 2016-08-29T11:05:52.200 回答
0

你试试

http://www.aviyehuda.com/2011/01/android-creating-links-using-linkfy/

// Recognize all of the default link text patterns 
    Linkify.addLinks(text, Linkify.ALL);

http://www.aviyehuda.com/2011/01/android-creating-links-using-linkfy/

TextView myCustomLink2 = new TextView(this);
Pattern pattern2 = Pattern.compile("[a-zA-Z]+");
myCustomLink2.setText("press one of these words to search it on google: Android Linkify dzone");
Linkify.addLinks(myCustomLink2,pattern2, "http://www.google.ie/search?q=", myMatchFilter, null);
于 2012-06-23T19:36:23.557 回答