Reputation: 48185
In the document for the method notifyDataSetChanged
of class BaseAdapter
noted that "Notifies the attached observers that the underlying data has been changed and any View reflecting the data set should refresh itself."
Supposed I changed the 3rd element in my string array (array data for the ListView
), what "any View reflecting the data set should refresh itself" means ? Does the 3rd view item in my list view be notified ?
Also, how is notifyDataSetChanged()
and getView()
concerned ?
Upvotes: 3
Views: 6089
Reputation: 87064
Supposed I changed the 3rd element in my string array (array data for the listview), what "any View reflecting the data set should refresh itself" means ?
It means that any view which shows/is based on/uses that data(the string array in your case) should be invalidated(remeasured, redrawn) in order to show the user the new set of data.
Does the 3rd view item in my list view be notified?
No, the parent ListView
will be notified. When you set the adapter on a ListView
, an observer(from the ListView
) will be set for that adapter. Calling notifyDataSetChanged
on the adapter will announce that observer from the ListView
that something has happen to the data. At this moment the ListView
will recreate the rows to show the new data.
Also, how is notifyDataSetChanged() and getView() concerned ?
I'm not sure I understand what you ask. The getView
method of an adapter is used by the ListView
to obtain a new row each time this is required. When you call notifyDataSetChanged
on the adapter this will trigger the observer in the ListView
. As it's time to recreate the list, the ListView
will call the getView
method of the adapter to show the necessary number of rows(the ones visible on the screen). So each time you call notifyDataSetChanged
the getView
method will be called for the visible rows.
Upvotes: 8