Android Rss Image Problem

眉间皱痕 提交于 2019-12-04 16:56:20
Eric Levine

Your RssItem class should not have the following:

private static ImageView image;

Replace that with:

private String imageUrl;

In your getRssItems method, use _imageE to get the value for imageUrl. Then use imageUrl as described below.

An ImageView will only display images stored locally on your device, so setting it to remote URL will not work. One solution can be found here: Android, Make an image at a URL equal to ImageView's image So, you will want to change from:

titleTv.setText(title);
image.setImageURI(uri);
contentTv.setText(content);

to:

titleTv.setText(title);
contentTv.setText(content);
try {
  //where imageUrl is what you pulled out from the rss feed
  Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageUrl).getContent());
  image.setImageBitmap(bitmap); 
} catch (MalformedURLException e) {
 //log exception here
} catch (IOException e) {
  //log exception here
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!