【问题标题】:How to make a link clickable in a Google Map Marker InfoWindowAdapter如何在 Google Map Marker Info Window Adapter 中使链接可点击
【发布时间】:2015-04-02 12:59:37
【问题描述】:

我在 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);
}

然后显示是正确的。我可以看到电话号码显示为链接,但我无法按下它... 我怎样才能让它打开拨号器?

【问题讨论】:

  • 按照我的回答尝试并从TextView中删除Linkify

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


【解决方案1】:

我终于做到了:

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

我设法做到了

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-02
    • 1970-01-01
    • 1970-01-01
    • 2013-10-15
    • 2017-10-08
    • 1970-01-01
    相关资源
    最近更新 更多