Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RecyclerView Adapter and ViewHolder update dynamically

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.

like image 377
Vendetta8247 Avatar asked Feb 16 '15 10:02

Vendetta8247


1 Answers

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!

like image 192
Xcihnegn Avatar answered Dec 25 '22 07:12

Xcihnegn