ArrayAdapter.NotifyDataSetChanged() is not working?

notifyDataSetChanged() won’t work for you. Reasons why

  1. Your adapter loses reference to your list.
  2. 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);

  1. 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 just adapter.notifyDataSetChanged()

     adapter = new myListAdapter(getActivity(), 0, myArrayList);
    
  2. Remove this line

    adapter.setItems (myArrayList);

Leave a Comment