如何在Google地图标记InfoWindowAdapter中点击链接

时间:2015-02-03 10:52:19

标签: android google-maps google-maps-markers phone-number linkify

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

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

在这个CustomInfoWindowAdapter中,我会显示一些文字并在找到电话号码时创建一个链接:

@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);
}

然后显示正确。我可以看到电话号码显示为链接,但我不能按它... 我如何才能打开拨号器?

1 个答案:

答案 0 :(得分:0)

我终于设法这样做了:

是的,但问题是电话解析;)

我设法做到了

this.map.setOnInfoWindowClickListener(new 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);
                    }
                }
            }
        }
    });
相关问题