infoWindow's image not showing on first click, but it works on second click

前端 未结 3 1929
逝去的感伤
逝去的感伤 2020-12-21 14:49

My android using the Google map android API,InfoWindow\'s image not showing on first click, but it works on second click

I customize the infoWindow using

         


        
3条回答
  •  死守一世寂寞
    2020-12-21 15:48

    i had the same problem using Glide rather than Picasso but i made a simple solution i don't know how efficient it will be but it works fine with me , anyway i would like to share it with you

    private Marker lastClicked;
    private HashSet markerIdSet=new HashSet<>();
    
    @Override
    public boolean onMarkerClick(Marker marker) {
        lastClicked=marker;
        if(!markerIdSet.contains(marker.getId()))
        {
            marker.showInfoWindow();
            marker.hideInfoWindow();
            Handler handler=new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    lastClicked.showInfoWindow();
                }
            },150);
            markerIdSet.add(marker.getId());
            return true;
        }
        else
        {
            marker.showInfoWindow();
            return true;
        }
    }
    

    so basically you will creat a HashSet of String (markerID) if the HashSet does not contain that marker id so we add it to the HashSet, and call the marker.showInfoWindow(); to show the infowindow and marker.hideInfoWindow(); to hide it then using Handler object, code execution will wait 150ms and then show the infowindow calling marker.showInfoWindow(); again ,doing that you will get the photo from the first click.

    technically you are forcing the code to click the marker twice automatically for the first time of each marker.

    please let me know if it worked.

提交回复
热议问题