我正在使用通用图像加载器将图像从指定的 url 加载到 imageview 中。但是,如果一个图像有多个可能的 url,例如图像可能存储在www.example.com/image.png
or中,www.example.com/image.jpg
或者www.example.com/image.gif
我需要显示第一个现有图像。
有任何想法吗?
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);
}
});
}