DataSetObserver 数据集改变了或变成无效时会调用这个方法。
public Abstact class DatasetObserver { // 整个数据集改变时会调用 onChanged 方法。比如在Cursor 上调用Cursor.requery() public void onChanged() { } // 这个数据集无效时会调用onInvalidated() 。比如在Cursor 上调用Cursor.deactivate() 或Cursor.close() 方法。 public void onInvalidated() { } }
Observable, 用于注册和反注册Observer对象。
abstract public class Observable<T> { protected final ArrayList<T> mObservers = new ArrayList<T>(); public vid registerObserver(T observer) {
if (observer == null) {
throw IllegalArgumentException();
}
synchronized(mObservers) {
if (mObservers.contains(observer)) {
throw IllegalStateException("Obseerver is already registered")!
}
mObservers.add(observer);
}
} public void unregisterObserver(T observer) {
if (observer == null) {
throw IllegalArgumentException("The observer is null");
}
synchronized (mObservers) {
int index = mObservers.indexOf(mObservers);
if (index == -1) {
throw IllegalStateException("Observer was not registered");
}
mObservers..remove(index);
}
} public unRegisterdAll() {
synchronized (mObservers) {
mObservers.clear();
}
} }