Android 自定义 InfoWindow Google Map v2 onclick 按钮?

标签 android google-maps onclick customization infowindow

您好,我想在 Android 应用程序中向我的 Google map 添加标记信息窗口。到目前为止,我已经添加了自定义信息窗口并且它具有图像和按钮。单击标记后我的目标然后显示信息窗口,然后用户单击窗口中的按钮关闭信息窗口并在单击按钮后执行一些 Activity 。但我无法识别用户何时单击标记信息窗口中的按钮。这是我的代码。请告诉我我的代码哪里出了问题。

googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {

                // Use default InfoWindow frame
                @Override
                public View getInfoWindow(Marker arg0) {
                    return null;
                }

                // Defines the contents of the InfoWindow
                @Override
                public View getInfoContents(Marker arg0) {



                    final View infoview = getLayoutInflater().inflate(R.layout.info_window,
                            null);

                    LatLng latLng = arg0.getPosition();                 

                    //tvLat.setText("Latitude:" + latLng.latitude);

                    //tvLng.setText("Longitude:" + latLng.longitude);

                     Button pickMe = (Button)infoview.findViewById(R.id.pickme);
                     pickMe.setOnClickListener(new Button.OnClickListener(){

                            @Override
                            public void onClick(View v) {
                                // TODO Auto-generated method stub
                                Toast.makeText(getApplicationContext(), "Requested Send", Toast.LENGTH_SHORT).show();

                            }});


                    //String reverceGeoCode=new GetLocationAddress().getAddress(String.valueOf(latLng.latitude), String.valueOf(latLng.longitude));
                    //Toast.makeText(getApplicationContext(), "Rev :"+reverceGeoCode, Toast.LENGTH_LONG).show();

                    return infoview;

                }
            });

这是我的 customInfo-window xml 文件

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"   
     >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Sajith Vijesekara"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_marginLeft="5dp"
         android:layout_marginTop="5dp"
         android:layout_marginBottom="5dp">
         <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight=".25"
        android:src="@drawable/driver" />

    <Button
        android:id="@+id/pickme"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight=".25"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="10dp"
        android:text="Pick Me" />

    </LinearLayout>   

</LinearLayout>

谢谢 萨 git

最佳答案

引用 the documentation :

Note: 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.

因此,当有人点击您的信息窗口中的 Button 时,您无法发现。欢迎您respond to clicks anywhere on the info window , 不过。

关于Android 自定义 InfoWindow Google Map v2 onclick 按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25058165/

相关文章:

android - 如何组成多个形状并添加浮雕?

android - 将文本设置为 fragment 内的 TextView

c# - 单击时如何使用 C# 编写的 ActiveX 控件在 JavaScript 中引发事件?

jquery - 打开文件对话框并通过单击图像提交图像

javascript - 淡入具有相同 id 的元素

android - 如何通过 adb shell 运行 QPython

android - ListView 元素的操作溢出菜单

java - 生成随机经纬度

javascript - 从 javascript 中的 csv 文件中的坐标使用 GoogleMaps API

laravel - file_get_contents() : SSL operation failed with code 1. OpenSSL 错误信息