Skip to content Skip to sidebar Skip to footer

Android - EBADF (Bad File Number) OnClickInfoMarker

I have searched related issues but can't find it. I create an InfoWindowMarker which shows Picture, Name and Address. Then i create OnInfoWindowClickListener that will showing Lati

Solution 1:

This might be a threading issue. Your viewGroup is returned before your image is load from the URL. An easy way to solve the problem is to use the third party image loading library Picasso.

Sample code:

 ImageView imageView = (ImageView)myContentsView.findViewById(R.id.ivRowImage);
 if (not_first_time_showing_info_window) {
     Picasso.with(getApplicationContext()).load("YOUR_IMG_URL").into(imageView);
 } else { // if it's the first time, load the image with the callback set
     not_first_time_showing_info_window=true;
     Picasso.with(getApplicationContext()).load("YOUR_IMG_URL").into(imageView,new InfoWindowRefresher(marker));
 }

And then you can have a private helper method to make sure the asynchronous shown in the first click:

 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() {}
    }

You can refer to this GitHub page for complete implementation: https://github.com/jbj88817/GoogleMap-InfoWindow-android/blob/master/app/src/main/java/com/bjiang/map_ex/MainActivity.java

If you really want to do it with ImageLoader, you can check out this post: http://androidfreakers.blogspot.com/2013/08/display-custom-info-window-with.html (But it is more complicated compared to using Picasso to load from URL)


Post a Comment for "Android - EBADF (Bad File Number) OnClickInfoMarker"