salvicode
salvicode

Reputation: 227

Android Universal image loader and several image's urls

I'm using an universal image loader to load images from specified url into imageview. But if there are several possible urls of one image e.g. image may be stored in www.example.com/image.png or www.example.com/image.jpg or www.example.com/image.gif and I need to display first existing image.

Any ideas?

Upvotes: 1

Views: 1022

Answers (1)

Rahul Matte
Rahul Matte

Reputation: 1181

If url are available in xml then you have to read those url using DOMParser or any other xml parser. Once you got the required url, feed it to the Universal Image Loader

ImageLoader imageLoader;
DisplayImageOptions options;
ImageView image;

private void loadImageFromURL(String url) {
        options = new DisplayImageOptions.Builder()
        .showStubImage(R.drawable.app_icon)
        .showImageForEmptyUrl(R.drawable.app_icon).cacheInMemory()
        .cacheOnDisc().build();

        imageLoader = ImageLoader.getInstance();
        imageLoader.init(ImageLoaderConfiguration.createDefault(this));
        imageLoader.displayImage(url, image, options,
                new ImageLoadingListener() {
            public void onLoadingComplete() {
                mProgressBar.setVisibility(View.INVISIBLE);

            }

            public void onLoadingFailed() {

                mProgressBar.setVisibility(View.INVISIBLE);
            }

            public void onLoadingStarted() {
                mProgressBar.setVisibility(View.VISIBLE);
            }
        });

    }

Upvotes: 1

Related Questions