有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java无法在自定义信息窗口上拨号

当我点击自定义信息窗口中的数字时,我无法启动手机的拨号程序。每次单击地图api v2上的标记时,都会出现此信息窗口。我想在marker的信息窗口中显示一个电话号码,然后单击它进入拨号屏幕(插入我的数字启动拨号器)

这是我的活动:

public View getInfoContents(Marker marker) {
    View v = getLayoutInflater().inflate(R.layout.infowindow_layout, null);

    //start phone call
    final TextView tvDialer =(TextView) v.findViewById(R.id.dialer);
    tvDialer.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
         String phoneNo= tvDialer.getText().toString();
         Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:" +phoneNo));
                callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(callIntent);
        }

    });
    //end phone call

    // Returning the view containing InfoWindow contents
    return v;

}

以下是我的XML:

<TextView
    安卓:id="@+id/dialer"
    安卓:layout_width="wrap_content"
    安卓:layout_height="wrap_content"
    安卓:autoLink="phone"
    安卓:text="1234567" />

你能帮帮我吗


共 (1) 个答案

  1. # 1 楼答案

    The info window that is drawn is not a live view. The view is rendered as an image (using View.draw(Canvas)) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (for example, after an image has loaded), call showInfoWindow(). Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.

    来自Google Maps V2文档:https://developers.google.com/maps/documentation/android/infowindows

    我建议在点击标记时启用拨号呼叫,或者如果您有多条信息,请在点击标记时显示一些浮动视图(一个小窗口),在此视图中显示相关信息,然后设置拨号呼叫

    但是,如果您仍然想要满足您的需求,那么有一个变通方法。 查看以下链接:Google Maps Android API v2 - Interactive InfoWindow (like in original android google maps)

    您可以使用OnInfo WindowClickListener来侦听信息窗口上的单击事件。要在地图上设置此侦听器,请调用GoogleMap。setOnInfoWindowClickListener(OnInfoWindowClickListener)