RecyclerView适配器和ViewHolder更新动态 [英] RecyclerView Adapter and ViewHolder update dynamically

查看:608
本文介绍了RecyclerView适配器和ViewHolder更新动态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使一个应用程序,将被从网络加载消息,将被动态地更新。我使用的是 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.

希望这是明确的!

这篇关于RecyclerView适配器和ViewHolder更新动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆