加载中...
The Wayback Machine - https://sup1a9wrlpyh5li9ro.vcoronado.top/web/20090218032548/http://developer.android.com:80/reference/java/util/Observable.html
public class

Observable

extends Object
java.lang.Object
   ↳ java.util.Observable
Known Direct Subclasses

Class Overview

Observable is used to notify a group of Observer objects when a change occurs.

Summary

Public Constructors
Observable()
Constructs a new Observable object.
Public Methods
synchronized void addObserver(Observer observer)
Adds the specified Observer to the list of observers.
synchronized int countObservers()
Returns the number of Observers in the list of observers.
synchronized void deleteObserver(Observer observer)
Removes the specified Observer from the list of observers.
synchronized void deleteObservers()
Removes all Observers from the list of observers.
synchronized boolean hasChanged()
Returns the changed flag for this Observable.
void notifyObservers()
If hasChanged() returns true, calls the update() method for every Observer in the list of observers using null as the argument.
void notifyObservers(Object data)
If hasChanged() returns true, calls the update() method for every Observer in the list of observers using the specified argument.
Protected Methods
synchronized void clearChanged()
Clears the changed flag for this Observable.
synchronized void setChanged()
Sets the changed flag for this Observable.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public Observable ()

Constructs a new Observable object.

Public Methods

public synchronized void addObserver (Observer observer)

Adds the specified Observer to the list of observers.

Parameters
observer the Observer to add

public synchronized int countObservers ()

Returns the number of Observers in the list of observers.

Returns
  • the number of observers

public synchronized void deleteObserver (Observer observer)

Removes the specified Observer from the list of observers.

Parameters
observer the Observer to remove

public synchronized void deleteObservers ()

Removes all Observers from the list of observers.

public synchronized boolean hasChanged ()

Returns the changed flag for this Observable.

Returns
  • true when the changed flag for this Observable is set, false otherwise

public void notifyObservers ()

If hasChanged() returns true, calls the update() method for every Observer in the list of observers using null as the argument. Afterwards calls clearChanged(). Equivalent to calling notifyObservers(null)

public void notifyObservers (Object data)

If hasChanged() returns true, calls the update() method for every Observer in the list of observers using the specified argument. Afterwards calls clearChanged().

Parameters
data the argument passed to update()

Protected Methods

protected synchronized void clearChanged ()

Clears the changed flag for this Observable. After calling clearChanged(), hasChanged() will return false.

protected synchronized void setChanged ()

Sets the changed flag for this Observable. After calling setChanged(), hasChanged() will return true.