Android自定义InfoWindow Google Map v2 onclick按钮? [英] Android custom InfoWindow Google Map v2 onclick button?

查看:221
本文介绍了Android自定义InfoWindow Google Map v2 onclick按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想添加标记信息窗口到我的谷歌地图在android应用程序。到目前为止我已添加自定义信息窗口,它有图像和button.My目标后点击标记,然后显示信息窗口,然后后用户点击窗口中的按钮关闭信息窗口,并点击按钮后做一些活动,但我不能识别当用户点击标记信息窗口中的按钮。这是我的代码。 Plz告诉我我的代码中哪里出了问题。

Hi i want to add marker info-window to my Google map in android application.So far i have add custom info window and it has Image and button.My target after click the marker then show the info-window and then after user click the button in window dismiss the info-window and do some activity after click the button.But i cant identify when user click button in marker info-window.This is my code. Plz tell me where is the wrong in my code.

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文件

And This is my customInfo-window xml file

    <?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>

感谢
Sajith

Thanks Sajith

推荐答案

引用文档


注意:绘制的信息窗口不是实时视图。该视图在返回时呈现为图像(使用View.draw(Canvas))。这意味着对视图的任何后续更改都不会反映在地图上的信息窗口中。稍后更新信息窗口(例如,在加载图像后),请调用showInfoWindow()。此外,信息窗口不会考虑任何典型的普通视图的交互性,例如触摸或手势事件。但是,您可以在整个信息窗口中听到通用的点击事件,如下面的部分所述。

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 时。欢迎您在信息窗口中在任何地方点击 ,但是。

Hence, you cannot find out when somebody taps on a Button in your info window. You are welcome to respond to clicks anywhere on the info window, though.

这篇关于Android自定义InfoWindow Google Map v2 onclick按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆