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 楼答案
来自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)