0

I am displaying custom infoWindow on marker by this reference. Now I am able to show custom infoWindow like enter image description here

But problem is that I am unable to get right click event on each button. e.g. when I click on button1 , it calls touchlistener of button2 and so on. My code is:

this.button1Listener = new OnInfoWindowElemTouchListener(
            button1, getResources().getDrawable(
                    R.drawable.ic_plusone_medium_off_client),
            getResources().getDrawable(
                    R.drawable.ic_plusone_tall_off_client)) {
        @Override
        protected void onClickConfirmed(View v, Marker marker) {
            // Here we can perform some action triggered after clicking the
            // button

            Toast.makeText(MapActivity.this, "Button1", Toast.LENGTH_SHORT)
                    .show();

        }
    };

this.button2Listener = new OnInfoWindowElemTouchListener(
                button2, getResources().getDrawable(
                        R.drawable.ic_plusone_medium_off_client),
                getResources().getDrawable(
                        R.drawable.ic_plusone_tall_off_client)) {
            @Override
            protected void onClickConfirmed(View v, Marker marker) {
                // Here we can perform some action triggered after clicking the
                // button

            Toast.makeText(MapActivity.this, "Button2", Toast.LENGTH_SHORT)
                    .show();

        }
    };

this.button3Listener = new OnInfoWindowElemTouchListener(
                button3, getResources().getDrawable(
                        R.drawable.ic_plusone_medium_off_client),
                getResources().getDrawable(
                        R.drawable.ic_plusone_tall_off_client)) {
            @Override
            protected void onClickConfirmed(View v, Marker marker) {
                // Here we can perform some action triggered after clicking the
                // button

            Toast.makeText(MapActivity.this, "Button3", Toast.LENGTH_SHORT)
                    .show();

        }
    }; and so on.......




this.button1.setOnTouchListener(button1Listener);
        this.button2.setOnTouchListener(button2Listener);
        this.button3.setOnTouchListener(button3Listener);
        .......
        // googleMap.setInfoWindowAdapter(null);
        googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {

        // Use default InfoWindow frame
        @Override
        public View getInfoWindow(Marker marker) {

            return null;
        }

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

            button1Listener.setMarker(marker);
            button2Listener.setMarker(marker);
            button3Listener.setMarker(marker);
            ......

            // We must call this to set the current marker and infoWindow
            // references
            // to the MapWrapperLayout
            mapWrapperLayout.setMarkerWithInfoWindow(marker, infoWindow);
            return infoWindow;

        }

    });

Please advise me, what I am doing wrong? Sometimes code works perfectly but most of the time it doesnt work. Thanks in advance.

Community
  • 1
  • 1
Umesh
  • 1,609
  • 1
  • 17
  • 28

2 Answers2

0

InfoWindow in Google map V2 is an Image, the library rendered all of them as an image. Read the "Note" in "Custom info windows" in maps Android API v2.

So all buttons which you add to will not work.

If you really want to do so, you have to do some code. I found one here

Community
  • 1
  • 1
Kuma
  • 2,703
  • 1
  • 12
  • 12
0

Finally, I solved this issue of mismatching click events of buttons. The problem is here.

// MapWrapperLayout initialization
    // 39 - default marker height
    // 20 - offset between the default InfoWindow bottom edge and it's content bottom edge 
    mapWrapperLayout.init(map, getPixelsFromDp(this, 39 + 20)); 

So I just changed:

 mapWrapperLayout.init(map, getPixelsFromDp(this, 39 + 20)); 

to

mapWrapperLayout.init(map, getPixelsFromDp(this, 0)); 

So there will not be any offset between infowindow bottom edge and it's content.

I hope this will help someone.

Umesh
  • 1,609
  • 1
  • 17
  • 28