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

前端 未结 3 1931
逝去的感伤
逝去的感伤 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:47

    First you can make a custom callback class to implement the com.squareup.picasso.Callback:

     private class InfoWindowRefresher implements Callback {
            private Marker markerToRefresh;
    
            private InfoWindowRefresher(Marker markerToRefresh) {
                this.markerToRefresh = markerToRefresh;
            }
    
            @Override
            public void onSuccess() {
                markerToRefresh.showInfoWindow();
            }
    
            @Override
            public void onError() {}
        }
    

    Second, declare a boolean variable in your activity:

    boolean not_first_time_showing_info_window;
    

    Third, implement the public View getInfoContents(Marker marker) method:

       @Override
       public View getInfoContents(Marker marker) {
          View v = getLayoutInflater().inflate(R.layout.custom_window, null);
          ImageView image = (ImageView)v.findViewById(R.id.image_view);
    
          if (not_first_time_showing_info_window) {
              Picasso.with(MainActivity.this).load("image_URL.png").into(image);
    
          } else {
              not_first_time_showing_info_window = true;                         
              Picasso.with(MainActivity.this).load("image_URL.png").into(image, new InfoWindowRefresher(marker));
          }
          return v;
       }
    

    You can also visit this GitHub page for completed implementation.

提交回复
热议问题