0

Can someone please explain me what is the difference between the following?

notifyDataSetChanged();

   notifyDataSetInvalidated();

    invalidateViews();

    invalidateData();

I have read the doc but wasn't sure what is the actual difference.

Elad Benda2
  • 13,852
  • 29
  • 82
  • 157

1 Answers1

1

They are so different. notifyDataSetChanged() is called when you've made some change inside your Adapter and the current data is still valid. notifyDataSetInvalidated() is called when some event happened that makes that the current Adapter is no longer available and observers should not expect any updates from it.

As per the documentation:

public void notifyDataSetInvalidated ()

Added in API level 1

Notifies the attached observers that the underlying data is no longer valid or available. Once invoked this adapter is no longer valid and should not report further data set changes.

Community
  • 1
  • 1
nKn
  • 13,691
  • 9
  • 45
  • 62
  • and how about invalidateData() and invalidateViews() ? – Elad Benda2 Apr 19 '14 at 14:15
  • I can't find any `invalidateData()` in the `Android` framework. Where have you seen it? For the second one, check this: http://stackoverflow.com/questions/10676720/is-there-any-difference-between-listview-invalidateviews-and-adapter-notify – nKn Apr 19 '14 at 14:18
  • 10x. `Most of the time you would want to use notifyDataSetChanged instead of invalidateViews, but it certainly depends on what you are trying to accomplish.` when will we actually use invalidateViews? in what cases? – Elad Benda2 Apr 19 '14 at 14:27
  • Honestly, I've never had to use `invalidateViews()` up until now, every design I've made uses `notifyDataSetChanged()`. I guess you just need to call the first if `notifyDataSetChanged()` fails and in very exceptional cases, such as you want your whole `ListView` layout to be recreated. – nKn Apr 19 '14 at 14:37