Search code examples
androidandroid-recyclerviewandroid-adapternotifydatasetchanged

Can I change a dataset inside a custom object and then notify the adapter?


What I want to know is, if I set an adapter to a recyclerview like this:

mRecyclerView.setAdapter(new myRecyclerAdapter(mCustomObject.getDataSet()));

Can I update the dataset and notify the adapter like this?

mCustomObject.getDataSet().add(XPTO);
myRecyclerAdapter.notifyDataSetChanged();

Or do I need to get the dataset inside the adapter?

Thanks in advance!


Solution

  • If mCustomObject.getDataSet() always returns the same object and doesn't create a new one, that should be enough. If it returns a new object every time, then the adapter has no way of updating the values to display.