android rss阅读器开发一点小技巧

时间:2021-04-21 20:52:25

这几天一直在学习开发Rss阅读器,遇到一个很坑的问题,InputSource这里总是出错。弄了好久,终于让我找到一个解决方法----看代码:

new Thread(){
@Override
public void run() {
try {
URL url = new URL(RSS_URL);
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
XMLReader xmlReader = parser.getXMLReader();
RssHandler rssHandler = new RssHandler();
xmlReader.setContentHandler(rssHandler);
Log.e("cuola1", xmlReader + "");
InputSource is = new InputSource(url.openStream());
Log.e("cuola55", is + "");
xmlReader.parse(is);
rssFeed=rssHandler.getFeed();
Log.e("ffdf",rssFeed.getItem(0).getTitle()+"");
showListView();
Log.e("ngjdgd","yunx");
new Handler().post(new Runnable() {
@Override
public void run() {

}
});
} catch (Exception e) {

} finally {
}
super.run();
}
}.start();

在新线程中去解析xml.