Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Observable

public class Observable
extends Object

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


Observable is used to notify a group of Observer objects when a change occurs. On creation, the set of observers is empty. After a change occurred, the application can call the notifyObservers() method. This will cause the invocation of the update() method of all registered Observers. The order of invocation is not specified. This implementation will call the Observers in the order they registered. Subclasses are completely free in what order they call the update methods.

See also:

Summary

Public constructors

Observable()

Constructs a new Observable object.

Public methods

void addObserver(Observer observer)

Adds the specified observer to the list of observers.

int countObservers()

Returns the number of observers registered to this Observable.

void deleteObserver(Observer observer)

Removes the specified observer from the list of observers.

void deleteObservers()

Removes all observers from the list of observers.

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

void clearChanged()

Clears the changed flag for this Observable.

void setChanged()

Sets the changed flag for this Observable.

Inherited methods

From class java.lang.Object

Public constructors

Observable

Added in API level 1
Observable ()

Constructs a new Observable object.

Public methods

addObserver

Added in API level 1
void addObserver (Observer observer)

Adds the specified observer to the list of observers. If it is already registered, it is not added a second time.

Parameters
observer Observer: the Observer to add.

countObservers

Added in API level 1
int countObservers ()

Returns the number of observers registered to this Observable.

Returns
int the number of observers.

deleteObserver

Added in API level 1
void deleteObserver (Observer observer)

Removes the specified observer from the list of observers. Passing null won't do anything.

Parameters
observer Observer: the observer to remove.

deleteObservers

Added in API level 1
void deleteObservers ()

Removes all observers from the list of observers.

hasChanged

Added in API level 1
boolean hasChanged ()

Returns the changed flag for this Observable.

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

notifyObservers

Added in API level 1
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).

notifyObservers

Added in API level 1
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 Object: the argument passed to update().

Protected methods

clearChanged

Added in API level 1
void clearChanged ()

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

setChanged

Added in API level 1
void setChanged ()

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

This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.