Search code examples
javaandroiduniversal-image-loader

Android: UIL I want to be able to load the same image multiple times


So whenever I am using the same image multiple times, it gets cancelled. So I hope you guys can help me I want to use the image as a marker icon

Here's my code:

String uri = "http://192.168.2.8:3000" + articlesArray.getJSONObject(i).getString("icon");

            ImageLoader imageLoader = ImageLoader.getInstance();

            imageLoader.loadImage(uri, new ImageLoadingListener() {
                @Override
                public void onLoadingStarted(String imageUri, View view) {
                    Log.e("tag", "onLoadingStarted");
                }

                @Override
                public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                    Log.e("tag", "onLoadingFailed");
                }

                @Override
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                    marker.setIcon(BitmapDescriptorFactory.fromBitmap(loadedImage));
                    Log.e("tag", "onLoadingComplete");
                }

                @Override
                public void onLoadingCancelled(String imageUri, View view) {
                    Log.e("tag", "onLoadingCancelled");
                }
            });

Solution

  • I solved my problem. For people who are still looking for an answer here is what I did:

    String uri = "http://192.168.2.8:3000" + articlesArray.getJSONObject(i).getString("icon");
    
                ImageLoader imageLoader = ImageLoader.getInstance();
                ImageSize targetSize = new ImageSize(37, 32);
                ImageAware imageAware = new NonViewAware(targetSize, ViewScaleType.CROP);
                imageLoader.displayImage(uri,imageAware, new ImageLoadingListener() {
                    @Override
                    public void onLoadingStarted(String s, View view) {
                        Log.e("tag", "onLoadingStarted");
                    }
    
                    @Override
                    public void onLoadingFailed(String s, View view, FailReason failReason) {
                        Log.e("tag", "onLoadingFailed");
                    }
    
                    @Override
                    public void onLoadingComplete(String s, View view, Bitmap bitmap) {
                        Log.e("tag", "onLoadingComplete");
                        marker.setIcon(BitmapDescriptorFactory.fromBitmap(bitmap));
                    }
    
                    @Override
                    public void onLoadingCancelled(String s, View view) {
                        Log.e("tag", "onLoadingCancelled");
                    }
                });