从android google maps v2上的custominfowindow获取价值?

时间:2014-03-24 11:15:26

标签: android google-maps google-maps-android-api-2 infowindow

我实现教程在Android设备上显示custominfowindow google maps v2 这里是mainActivity.java中的代码

final Marker hamburg = googleMap.addMarker(new MarkerOptions().position(HAMBURG)
                        .title("Hamburg"));
            markers.put(hamburg.getId(), "http://img.india-forums.com/images/100x100/37525-a-still-image-of-akshay-kumar.jpg");

以下代码是同一文件中的自定义信息类

private class CustomInfoWindowAdapter implements InfoWindowAdapter{

        private View view;

        public CustomInfoWindowAdapter() {
            view = getLayoutInflater().inflate(R.layout.custom_info_window,
                    null);
        }

        @Override
        public View getInfoContents(Marker marker) {
            if (MapV2InfoWindow.this.marker != null
                    && MapV2InfoWindow.this.marker.isInfoWindowShown()) {
                MapV2InfoWindow.this.marker.hideInfoWindow();
                MapV2InfoWindow.this.marker.showInfoWindow();
            }
            return null;
        }

        @Override
        public View getInfoWindow(final Marker marker) { 
            MapV2InfoWindow.this.marker = marker;

            String url = null;

            if (marker.getId() != null && markers != null && markers.size() > 0) {
                if ( markers.get(marker.getId()) != null &&
                        markers.get(marker.getId()) != null) {
                    url = markers.get(marker.getId());
                }
            }
            final ImageView image = ((ImageView) view.findViewById(R.id.badge));

            if (url != null && !url.equalsIgnoreCase("null")
                    && !url.equalsIgnoreCase("")) {
                imageLoader.displayImage(url, image, options,
                        new SimpleImageLoadingListener() {
                            @Override
                            public void onLoadingComplete(String imageUri,
                                    View view, Bitmap loadedImage) {
                                super.onLoadingComplete(imageUri, view,
                                        loadedImage);
                                getInfoContents(marker);
                            }
                        });

            } else {
                image.setImageResource(R.drawable.ic_launcher);
            }

            final String title = marker.getTitle();
            final TextView titleUi = ((TextView) view.findViewById(R.id.title));
            if (title != null) {
                titleUi.setText(title);
            } else {
                titleUi.setText("");
            }

            final String snippet = marker.getSnippet();
            final TextView snippetUi = ((TextView) view
                    .findViewById(R.id.snippet));
            if (snippet != null) {
                snippetUi.setText(snippet);
            } else {
                snippetUi.setText("");
            }

            //final String txtGambarPp=url;
            final TextView txtGambarPpUi = ((TextView) view
                    .findViewById(R.id.txtImagePpSource));
            if (snippet != null) {
                txtGambarPpUi.setText(url);
            } else {
                txtGambarPpUi.setText("kosong");
            }
            return view;
        }
    }

customInfowindow.xml(LinearLayout)

<ImageView
    android:id="@+id/badge"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_marginRight="5dp"
    android:adjustViewBounds="true" >
</ImageView>

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

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:singleLine="true"
        android:textColor="#ff000000"
        android:textSize="14dp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/snippet"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#ff7f7f7f"
        android:textSize="14dp" />
    <!-- I add this textview to show information about image -->
    <TextView
        android:id="@+id/txtImagePpSource"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="source image"/>
</LinearLayout>

我成功运行这个应用程序并在infowindow中显示信息,如果我想从标题中获取价值我只需要调用marker.getTitle并成功返回标题,但我想在infowindow中添加除标题和片段之外的信息,所以我添加我的xml with textview(在这种情况下我设置id textview是@+id/txtImagePpSource)当我运行应用程序仍然成功但我的问题我想从infowindow事件点击的textview获取价值?我如何实现,如果我想从标题获取值只需调用marker.getTitle,那么如何使用 txtImagePpSource

感谢

0 个答案:

没有答案