RecyclerView适配器和ViewHolder更新动态适配器、动态、RecyclerView、ViewHolder

2023-09-06 02:39:17 作者:一梦荼蘼

我想使一个应用程序,将被从网络加载消息,将被动态地更新。我使用的是 RecyclerView CardView 中显示的内容。我用 Jsoup 解析的网站。我不认为我的code是必要的,因为我的问题是理论多于实际。我想用了解动态更新的过程 notifyDataSetChanged()。在我的主要活动,我得到的所有标题,将它们添加到列表中。但是,我需要等待,直到所有的项目将被加载到开始显示他们。我真的AP preciate如果有人可以张贴什么,我试图做的,因为我无法找到很多相关信息相结合 ViewHolder ,适配器 RecyclerView

I am trying to make an app that will be loading news from the network and will be updating dynamically. I am using a RecyclerView and CardView to display the content. I use Jsoup to parse sites. I don't think that my code is needed because my question is more theoretical than practical. I want to understand the process of dynamic updating using notifyDataSetChanged(). In my main activity I get all the headers and add them to list. But I need to wait untill all the items are loaded to start displaying them. I would really appreciate if someone could post a sample code of what I'm trying to do because I couldn't find a lot of information about combining ViewHolder, Adapter and RecyclerView.

推荐答案

在你的 RecyclerView适配器,你应该有一个的ArrayList ,也是一种方法 addItemsToList(项目)来列表项添加到的ArrayList 。然后,您可以通过电话 adapter.addItemsToList(项目)动态添加列表项。添加到您的所有列表项后,的ArrayList ,那么你可以调用 adapter.notifyDataSetChanged()来显示你的列表中。

In your RecyclerView adapter, you should have a ArrayList and also one method addItemsToList(items) to add list items to the ArrayList. Then you can add list items by call adapter.addItemsToList(items) dynamically. After all your list items added to the ArrayList then you can call adapter.notifyDataSetChanged() to display your list.

希望这是明确的!