我正在尝试为Android制作新闻阅读器,但我无法找到如何解析每个rss项目的缩略图。我是否必须填充缩略图的每个URL并保存它们才能使用它们,或者我可以将它们与网址一起使用?这是Feed的代码
public class RssFeed implements Parcelable {`
private String title;
private String link;
private String description;
private String language;
private ArrayList<RssItem> rssItems;
public RssFeed() {
rssItems = new ArrayList<RssItem>();
}
public RssFeed(Parcel source) {
Bundle data = source.readBundle();
title = data.getString("title");
link = data.getString("link");
description = data.getString("description");
language = data.getString("language");
rssItems = data.getParcelableArrayList("rssItems");
}
@Override
public void writeToParcel(Parcel dest, int flags) {
Bundle data = new Bundle();
data.putString("title", title);
data.putString("link", link);
data.putString("description", description);
data.putString("language", language);
data.putParcelableArrayList("rssItems", rssItems);
dest.writeBundle(data);
}
public static final Parcelable.Creator<RssFeed> CREATOR = new Parcelable.Creator<RssFeed>() {
public RssFeed createFromParcel(Parcel data) {
return new RssFeed(data);
}
public RssFeed[] newArray(int size) {
return new RssFeed[size];
}
};
这是Rss阅读器:(我还创建了一个存储值的对象RssItem。)
public class RssReader {
public static RssFeed read(URL url) throws SAXException, IOException {
return read(url.openStream());
}
public static RssFeed read(InputStream stream) throws SAXException, IOException {
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
XMLReader reader = parser.getXMLReader();
RssHandler handler = new RssHandler();
InputSource input = new InputSource(stream);
reader.setContentHandler(handler);
reader.parse(input);
return handler.getResult();
} catch (ParserConfigurationException e) {
throw new SAXException();
}
}
public static RssFeed read(String source) throws SAXException, IOException {
return read(new ByteArrayInputStream(source.getBytes()));
}
}