notifyDataSetChanged()
won’t work for you. Reasons why
- Your adapter loses reference to your list.
- Always creating and adding a new list to the Adapter. Do like this:
initialize the ArrayList while declaring globally.
ArrayList<MyItemType> myArrayList=new ArrayList<>();
// as a global variable
Add List to the adapter directly without checking null and empty condition. Set the adapter to the list directly(don’t check for any condition)
myListView.setAdapter(adapter);
-
Add data to the myArrayList Every time(if your data is completely new, then you can call adapter.clear() and myArrayList.clear() before actually adding data to the list) but don’t set the adapter
i.e If the new data is populated in the myArrayList, then justadapter.notifyDataSetChanged()
adapter = new myListAdapter(getActivity(), 0, myArrayList);
-
Remove this line
adapter.setItems (myArrayList);