ここでは、JSONを解析して画像のURLを取得した画像を表示しています。
今までは問題なく動作します。
コードは次のとおりです。
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();
}
imageUrlが空の場合、代替画像のURLを表示したいと思います。
これどうやってするの ??次のコードを試しましたが、以下のコードに代替画像、つまりtestUrlが表示されません。それでもSystem.out.println("image empty and showing alternate image");
logcatには出力されません。
単独で解決: 正しいコードは次のとおりです。
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();
}
}