Create a custom folder in the message list

Custom messages are maintained in custom folders. To perform operations on custom messages, your BlackBerry® device application must register at least one custom folder.

  1. Import the required classes and interfaces.
    import net.rim.blackberry.api.messagelist.*;
    import net.rim.device.api.collection.ReadableList;
  2. Create a class that implements the ApplicationMessage interface.
    public class MLSampleMessage implements ApplicationMessage
  3. Obtain a reference to an ApplicationMessageFolderRegistry object.
    ApplicationMessageFolderRegistry reg = 
       ApplicationMessageFolderRegistry.getInstance();
  4. Invoke ApplicationMessageFolderRegistry.registerFolder() to register a custom folder for each collection of messages.
    // collections of MLSampleMessage instances 
    ReadableList inboxMessages = messages.getInboxMessages(); 
    ReadableList deletedMessages = messages.getDeletedMessages(); 
    
    ApplicationMessageFolder inboxFolder = reg.registerFolder( 
       INBOX_FOLDER_ID, 
       "Inbox", 
       inboxMessages );
    ApplicationMessageFolder deletedFolder = reg.registerFolder( 
       DELETED_FOLDER_ID, 
       "Deleted Messages",   
       deletedMessages, 
       false );
  5. Invoke ApplicationMessageFolder.addListener() to add a listener so that your application can be notified when specific folder events occur. In the following code sample, the application listens for deleted messages. For a list of all actions that you can listen for, see the documentation for the ApplicationMessageFolderListener class in the API reference for the BlackBerry® Java® SDK.
    deletedFolder.addListener( this, 
       ApplicationMessageFolderListener.MESSAGE_DELETED );
  6. Create a class that implements the ApplicationMessageFolderListener interface.
    public class AppFolderListener implements ApplicationMessageFolderListener
  7. Implement ApplicationMessageFolderListener.actionPerformed() to perform actions when a folder event occurs.
    public void actionPerformed( int action, ApplicationMessage[] messages, 
       ApplicationMessageFolder folder ) 
    {
       // check if action was performed on multiple messages
       if( messages.length == 1 )  
       {
         switch( action ) 
         {
            case ApplicationMessageFolderListener.MESSAGE_DELETED:
               messageStore.deleteInboxMessage( message );
       ...
  8. Invoke ApplicationMessageFolderRegistry.setRootFolderName() to specify the name of the root folder for your application's custom folders. The name of the root folder appears in the View Folder dialog box of the Messages application when an application registers more than one application message folder.
    reg.setRootFolderName( "ML Sample" );

Was this information helpful? Send us your comments.