Android:自定义工具提示Google Maps中的按钮单击事件

Android:自定义工具提示Google Maps中的按钮单击事件,android,google-maps,tooltip,onclicklistener,layout-inflater,Android,Google Maps,Tooltip,Onclicklistener,Layout Inflater,我正试图在Android平台上的谷歌地图上为我的标记制作一个自定义工具提示 我试过一些东西,这就是我现在所拥有的 充气机等级: private class InfoHandler implements GoogleMap.InfoWindowAdapter, View.OnClickListener { @Override public View getInfoWindow(Marker marker) { return null; } @Ov

我正试图在Android平台上的谷歌地图上为我的标记制作一个自定义工具提示

我试过一些东西,这就是我现在所拥有的

充气机等级:

private class InfoHandler implements GoogleMap.InfoWindowAdapter, View.OnClickListener {

    @Override
    public View getInfoWindow(Marker marker) {
        return null;
    }

    @Override
    public View getInfoContents(Marker marker) {
        View v = layoutInflater.inflate(R.layout.tooltip_brewer, null);

        TextView tvLat = (TextView) v.findViewById(R.id.tv_title);
        TextView tvLng = (TextView) v.findViewById(R.id.tv_snippet);
        Button button = (Button) v.findViewById(R.id.btn_button);
        tvLat.setText("TestTooltip");
        tvLng.setText("TestTooltip 1");
        button.setOnClickListener(this);

        return v;
    }

    @Override
    public void onClick(View view) {
        Log.d(Constants.TAG,  "Test 01");
    }
}
与标记的连接:

public void setInfoWindow(LayoutInflater inflater) {
        this.layoutInflater = inflater;
        map.setInfoWindowAdapter(new InfoHandler());
    }
工具提示XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="10dp"
    android:orientation="vertical">

    <TextView
        android:id="@+id/tv_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Title"
        android:textSize="18sp" />

    <TextView
        android:id="@+id/tv_snippet"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="snippet" />

</LinearLayout>

<Button
    android:id="@+id/btn_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

</LinearLayout>


现在一切正常接受我无法在工具提示中的按钮上执行单击事件。有人能解决这个问题吗?

这是因为它不是实时视图,所以你不能做你想做的事情

注意:绘制的信息窗口不是实时视图。观点是 在创建时渲染为图像(使用View.draw(Canvas)) 返回。这意味着不会对视图进行任何后续更改 被地图上的信息窗口反映出来。更新信息窗口的步骤 稍后(例如,在加载图像后),调用showInfoWindow()。 此外,信息窗口将不考虑任何交互性 通常用于正常视图,如触摸或手势事件。然而你 可以在整个信息窗口上侦听一般单击事件,如下所示 在下面的章节中描述

查看文档

可能存在的副本