TheDevMan
TheDevMan

Reputation: 5954

Open Custom Infowindows in Android Google maps v2

I am trying open Custom InfoWindows (that used InfoWindowAdapter) by default. I mean immediately after the map is loaded. Is this possible? if so how?

I have the following:

googleMap.setInfoWindowAdapter(new CustomInfoWindowAdapter());
    final Marker mark = googleMap.addMarker(new MarkerOptions().position(latLong)
                    .title("Last Updated:"));
        markers.put(mark.getId(), url);

My custom info window adapter

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 (MainActivity.this.marker != null
                && MainActivity.this.marker.isInfoWindowShown()) {
            MainActivity.this.marker.hideInfoWindow();
            MainActivity.this.marker.showInfoWindow();
        }
        return null;
    }

    @Override
    public View getInfoWindow(final Marker marker) 
    {
        MainActivity.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("");
        }

        return view;
    }
}

Above shows up a pin and I have click to get the window information. I want to show up the custom infowindow automatically.

Thank!

Upvotes: 1

Views: 6701

Answers (1)

sujith s
sujith s

Reputation: 914

markers.showInfoWindow();

For more detail go through the link

Upvotes: 1

Related Questions