简体   繁体   English

将RSS XML提要解析为列表视图

[英]Parsing RSS XML feed into a listview

Getting straight to the point, I'm new to this and trying to use this https://github.com/matshofman/Android-RSS-Reader-Library library to parse an rss feed and put all that into a listview. 直截了当,我是新手,并尝试使用此https://github.com/matshofman/Android-RSS-Reader-Library库解析rss feed并将其全部放入列表视图。 (I don't mind if you give me an alternate solution to this though. I picked this simply because it looked like it would be easier to understand and less work....) (不过,我不介意您是否为此提供替代解决方案。我之所以选择它只是因为它看起来更容易理解,而且工作量更少。)

MY problem is that I'm not sure how to do it, and when I read up on it on google it's either darn confusing or Eclipse says there's something wrong with it and gives me an error. 我的问题是我不确定如何做到这一点,当我在Google上阅读它时,这真是令人困惑,或者Eclipse表示它有问题,并给了我一个错误。

So :: can someone please explain to me, how I should go about doing this. 所以::有人可以向我解释一下,我应该怎么做。 I understand how to put a URL into this feed, and generally how listviews work, 我了解如何在此供稿中添加URL,以及通常列表视图的工作方式,

but I'm getting stumped on passing the data that the library extracts from the feed and passing it into my listview. 但我对传递库从提要中提取的数据并将其传递到我的列表视图感到困惑。 I don't have a clue how to write out java code that tells it to take data that this library passed and say, put it into this string. 我不知道如何编写Java代码来告诉它获取该库传递的数据,然后说将其放入此字符串中。

I'm also confused about how a listadapter / adapter works. 我也对listadapter /适配器的工作方式感到困惑。 I think I understand how to write it, but all my past attempts have given me errors and I'm not sure what's the problem there. 我想我知道怎么写,但是我过去的所有尝试都给了我错误,而且我不确定那里是什么问题。

It would also be nice if someone could explain how the list_layout thing works out. 如果有人可以解释list_layout的工作原理也很好。 By that, I mean when you create a new xml file and define how one row of the listview looks, but I don't see how it gets linked up with the main xml file with a single listview. 通过这种方式,我的意思是当您创建一个新的xml文件并定义listview的一行的外观时,但是我看不到如何通过单个listview将其与主xml文件链接起来。

Thanks for helping me out - it's a school project.... 感谢您的帮助-这是一个学校项目。

(btw, please be simple with the explanations. I think the main problem i'm having is that a lot of the tutorials like using very technical language, and it ends up not getting the point across to me. Even if you give me a chunk of code, and tell me all that parses my url, that's all i need.) (顺便说一句,请简单讲解。我认为我遇到的主要问题是许多教程都喜欢使用非常技术性的语言,但最终并没有使我明白这一点。即使您给了我一个代码,然后告诉我所有解析我的网址的信息,这就是我所需要的全部。)

A ListView needs an Adapter to know what the data is and how much of the data there is. ListView需要一个适配器才能知道什么是数据以及多少数据。 The ListView asks the adapter for a view to display a single item using the adapter's method getView(....). ListView使用适配器的方法getView(....)向适配器提供一个视图,以显示单个项目。 In this method you should inflate your view (the item) using the getLayoutInflater().inflate(..). 在此方法中,您应该使用getLayoutInflater()。inflate(..)使视图(项目)膨胀。 You then get a view for which you can get the specific sub-views by using the findViewById(...) method on that view. 然后,您将获得一个视图,可以通过在该视图上使用findViewById(...)方法来获取特定的子视图。 Of each sub-view you set the value of a part of your item. 在每个子视图中,您可以设置项目一部分的值。

In order to avoid having to inflate a view for each and every item the ListView recycles item views whenever possible, therefore the method getView(...) receives a view, if that view is not null you can use that view instead of inflating a new view. 为了避免必须为每个项目都增加一个视图,ListView会在可能的情况下回收项目视图,因此getView(...)方法会收到一个视图,如果该视图不为null,则可以使用该视图来代替为新的观点。

While reading your data, or when you have read all your data, you need to tell the adapter that the data has changed, which then tells your ListView that it needs to redisplay data. 在读取数据或读取所有数据时,您需要告诉适配器数据已更改,然后告诉您的ListView它需要重新显示数据。 You tell your adapter by calling notifyDataSetChanged(). 您可以通过调用notifyDataSetChanged()来告知适配器。

There is a Google I/O session on the ListView, maybe that might be interesting to watch: http://www.google.com/intl/nl/events/io/2010/sessions/world-of-listview-android.html ListView上有一个Google I / O会话,也许值得一看: http : //www.google.com/intl/nl/events/io/2010/sessions/world-of-listview-android。 html

In you android-sdk under /samples/android-xx/ there is a sample called "XmlAdapter" which contains a RSS-feed activity. 在/ samples / android-xx /下的android-sdk中,有一个名为“ XmlAdapter”的示例,其中包含一个RSS feed活动。 Could be a helpful alternative. 可能是一个有用的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM