仅从 rss 中获取一项
我想在我的 Android 应用程序中显示每天来自 rss 的单个项目。 现在我不想用列表视图构建一个复杂的RSS阅读器,所以我只想每天获取一个项目,这可能吗? 谢谢
I want to show in my Android app, a single item from rss each day.
Now I dont' want to build a complex rss reader with a listview and so, I just want to get a single item each day, is it possible?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个非常普遍的问题,但我会尽力回答。您需要做三件事:获取 xml、解析 xml,然后显示它。
为了获取 XML,我建议使用 AsyncTaskLoader 和 HttpUrlConnection 下载它。
为了解析 XML,您有几个选项。您可以使用 SAX 解析器。这就是我喜欢的方式。您可以查看此教程 关于如何使用 SAX 解析器。或者,如果您更喜欢使用 DOM 解析器,您可以查看此 教程。
一旦解析完成,您就可以将 TextView 的内容设置为您解析的内容。
我没有这一切的示例,因为这基本上是一个完整的 Android 应用程序。但根据我所提供的内容,您应该已经足够开始并自己构建一个。
This is a very general question, but I'll do my best to respond to it. You'll need to do three things: get the xml, parse the xml, and then display it.
For getting the XML I recommend using an AsyncTaskLoader and an HttpUrlConnection to download it.
For parsing the XML you have a few options. You can use a SAX parser. This is the way I like to do it. You can checkout this tutorial on how to use the SAX parser. Or if you prefer to use a DOM parser, you can checkout this tutorial.
Once it's been parsed, you can just set the contents of a TextView to whatever you parsed.
I don't have an example of all this because this is bascially an entire android app. But with what I've given you, you should have enough to get started and build one on your own.
使用 http 获取 feed 并解析 xml 可以使用第三方库轻松完成。
下面是我用来获取 Picasa 精选照片源并解析 rss 项目以提取标题和内容 url 的代码。
我也在这里写了关于这个的博客
http://blog.androidquery.com/2011 /09/simler-and-easier-xml-parsing-in.html
Fetching the feed with http and parsing the xml can be easily done with a third party library.
Here's code that I used to fetch the Picasa featured photos feed, and parse the rss item to extract the title and the content url.
I also blogged about this here
http://blog.androidquery.com/2011/09/simpler-and-easier-xml-parsing-in.html