Create A Collection Listener To Notify The System When A Collection Changes; Remove A Collection Listener That Notifies The System When A Collection Changes - Blackberry JAVA DEVELOPMENT ENVIRONMENT - - DEVELOPMENT GUIDE Manual

Version: 4.7.0
Hide thumbs Also See for JAVA DEVELOPMENT ENVIRONMENT - - DEVELOPMENT GUIDE:
Table of Contents

Advertisement

Development Guide
_persist.setContents( _contacts );
_persist.commit();
}

Create a collection listener to notify the system when a collection changes

The system invokes CollectionEventSource.addCollectionListener() to create a
CollectionListener for each SyncCollection the BlackBerry® device application makes available for wireless
backup.
1.
Import the net.rim.device.api.util.ListenerUtilities class.
2.
Import the following interfaces:
• java.util.Vector
• net.rim.device.api.collection.CollectionEventSource
• net.rim.device.api.collection.CollectionListener
• net.rim.device.api.synchronization.SyncCollection
3.
Create a private vector object to store the collection of SyncCollection listeners for the BlackBerry device application.
private Vector _listeners;
_listeners = new CloneableVector();
4.
Implement the CollectionEventSource.addCollectionListener() method, making sure the method
adds a CollectionListener to the Vector that contains listeners. In the following code sample, we implement
CollectionEventSource.addCollectionListener() to invoke
ListenerUtilities.fastAddListener() to add a listener to theVector that contains listeners.
public void addCollectionListener(Object listener)
{
_listeners = ListenerUtilities.fastAddListener( _listeners, listener );
}

Remove a collection listener that notifies the system when a collection changes

When a CollectionListener is no longer required, the system invokes
CollectionEventSource.removeCollectionListener.
1.
Import the following classes:
• net.rim.device.api.util.ListenerUtilities
• java.util.Vector
2.
Import the following interfaces:
• net.rim.device.api.collection.CollectionEventSource
• net.rim.device.api.collection.CollectionListener
3.
Implement the following interfaces:
• net.rim.device.api.collection.CollectionEventSource
50
Collections

Advertisement

Table of Contents
loading

This manual is also suitable for:

Java development environment

Table of Contents