If by any chance you landed on this thread and wondering why adapter.invaidate()
or adapter.clear()
methods are not present in your case then maybe because you might be using RecyclerView.Adapter
instead of BaseAdapter
which is used by the asker of this question. If clearing the list
or arraylist
not resolving your problem then it may happen that you are making two or more instances of the adapter
for ex.:
MainActivity
...
adapter = new CustomAdapter(list);
adapter.notifyDataSetChanged();
recyclerView.setAdapter(adapter);
...
and
SomeFragment
...
adapter = new CustomAdapter(newList);
adapter.notifyDataSetChanged();
...
If in the second case you are expecting a change in the list of inflated views in recycler view then it is not gonna happen as in the second time a new instance of the adapter
is created which is not attached to the recycler view. Setting notifyDataSetChanged
in the second adapter is not gonna change the content of recycer view. For that make a new instance of the recycler view in SomeFragment and attach it to the new instance of the adapter.
SomeFragment
...
recyclerView = new RecyclerView();
adapter = new CustomAdapter();
recyclerView.setAdapter(adapter);
...
Although, I don't recommend making multiple instances of the same adapter and recycler view.