Adapter(17)notifyDataSetChanged与notifyDataSetInvalidated区别

在代码中:

 1 public abstract class BaseAdapter implements ListAdapter, SpinnerAdapter {
 2     private final DataSetObservable mDataSetObservable = new DataSetObservable();
 3 
 4     ...  
 5     /**
 6      * Notifies the attached observers that the underlying data has been changed
 7      * and any View reflecting the data set should refresh itself.
 8      */
 9     public void notifyDataSetChanged() {
10         mDataSetObservable.notifyChanged();
11     }
12 
13     /**
14      * Notifies the attached observers that the underlying data is no longer valid
15      * or available. Once invoked this adapter is no longer valid and should
16      * not report further data set changes.
17      */
18     public void notifyDataSetInvalidated() {
19         mDataSetObservable.notifyInvalidated();
20     }
21     ...
22 }

 

notifyDataSetChanged :  

  通知它的观察者它监控的数据集数据有变化(如更新,添加,删除),要该数据对应的view更新。

notifyDataSetInvalidated: 

  通知它的观察者它监控的数据集不在有效,不在可用,一但调用这个方法之后,adapter就不在可用了,更不要在之后调用notifyDataSetChanged();

 

posted @ 2016-08-26 13:37  f9q  阅读(221)  评论(0)    收藏  举报