如何在 Google 地图标记 InfoWindowAdapter 中使 link 可点击

How to make a link clickable in a Google Map Marker InfoWindowAdapter

我在 Google 地图上显示了几个标记。 当我点击一个标记时,它会打开一个自定义的 InfoWindowAdapter

    this.map.setInfoWindowAdapter(new CustomInfoWindowAdapter(getLayoutInflater()));

在这个 CustomInfoWindowAdapter 中,我显示一些文本并在找到 phone 数字时创建一个 link:

@Override
public View getInfoContents(Marker marker) {
    if (this.popup == null) {
        this.popup = inflater.inflate(R.layout.poi_marker, null);
    }

    TextView tv = (TextView) popup.findViewById(R.id.title);

    tv.setText(marker.getTitle());
    tv = (TextView) popup.findViewById(R.id.snippet);
    tv.setText(marker.getSnippet());
    Linkify.addLinks(tv, Linkify.PHONE_NUMBERS);

    return(popup);
}

显示正确。我可以看到 phone 数字显示为 link,但我无法按它... 我怎样才能让它打开拨号器?

我终于做到了:

是的,但问题是 phone 解析 ;)

我做到了

this.map.setOnInfoWindowClickListener(新的 OnInfoWindowClickListener() {

        @Override
        public void onInfoWindowClick(Marker marker) {
            final String description = marker.getSnippet();
            if (!TextUtils.isEmpty(description)) {
                final Spannable span = Spannable.Factory.getInstance().newSpannable(description);
                if (Linkify.addLinks(span, Linkify.PHONE_NUMBERS)) {
                    final URLSpan[] old = span.getSpans(0, span.length(), URLSpan.class);
                    if (old != null && old.length > 0) {
                         Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(old[0].getURL()));
                         startActivity(intent);
                    }
                }
            }
        }
    });