Reputation: 2938
Here i am displaying a image where image url is fetched by parsing JSON.
It works fine up to now.
Here is the code :
ImageView iconImageView = (ImageView) convertView
.findViewById(R.id.listicon);
//TAG_IMAGE is tag name of image url which i got from parsing JSON
String imageUrl = (String) data.get(TAG_IMAGE);
try {
Drawable image = ImageOperations(getApplicationContext(),
imageUrl);
iconImageView.setImageDrawable(image);
} catch (Exception ex) {
ex.printStackTrace();
}
I wan to display the alternative image url if imageUrl is empty.
How can i do this ??
I had tried the following code but it doesnot display the alternate image i.e testUrl in below code. Even it doesnot print System.out.println("image empty and showing alternate image");
in logcat too.
Solved on its own: The correct code works for me is:
String imageUrl = (String) data.get(TAG_IMAGE);
if (imageUrl.equals("") ) {
System.out.println("image empty");
String rUrl = "http://www.windypress.com/mediakit/moon/icon/moon-icon-full-72.png";
try {
Drawable image2 = ImageOperations(getApplicationContext(),
rUrl);
iconImageView.setImageDrawable(image2);
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
System.out.println("has image");
try {
Drawable image1 = ImageOperations(getApplicationContext(),
imageUrl);
iconImageView.setImageDrawable(image1);
} catch (Exception ex) {
ex.printStackTrace();
}
}
Upvotes: 0
Views: 677
Reputation: 3804
Print your imageUrl
before checking. imageUrl
is not null. It may be empty but not null. Check for imageUrl.length() > 0
Upvotes: 1