RecyclerView Adapter and ViewHolder update dynamically

寵の児 提交于 2019-12-18 02:47:31

问题


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.


回答1:


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.

Hope this is clear!



来源:https://stackoverflow.com/questions/28539666/recyclerview-adapter-and-viewholder-update-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!