My AsyncTaskLoader is loading data from a remote server. When new data arrives, naturally a call is made to onLoadFinished
. At this point I don't know how to give the new data to the RecyclerView.Adapter
. Calling notifyDataSetChanged
does not give it the new data: it simply tells it there is new data. So any advice on how I might do this? Right now the best I can think of is to create my own setData
method in my implementation of RecyclerView.Adapter
as
public void setData(List<MyObject> data){
if(null != data && !data.isEmpty()){
synchronized(mItems){
mItems.clear();
mItems.addAll(data);
}
notifyDataSetChanged();
}
}
Is my idea the best there is? Or is there a more sound way of doing this?