Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Implement the ViewListener interface

by BlackBerry Development Advisor ‎02-16-2010 01:08 PM - edited ‎02-17-2010 03:55 PM (1,051 Views)


This article applies to the BlackBerry® Java™ Development Environment (JDE).


The ViewListener interface allows an application to listen for view events on messages, such as the opening or closing of a message. To implement the ViewListener interface, complete the following steps:

1. Include the ViewListener interface by implementing ViewListener to the following class:
public class ViewMessages implements ViewListener

2. Add the listener to the Session. For example,

 3. The application must implement the methods that exist in the ViewListener Interface:

public void close(MessageEvent e)
public void open(MessageEvent e)

4. Set your project to Auto-Start by completing the following:
  • In the BlackBerry JDE, right-click the name of the project and select Properties.
  • On the Application tab, select the Auto-run on Start-up check box.
  • Click OK.
  • The following example implements the ViewListener interfaces and displays a Dialog box informing the user of the MessageEvent (open or close) that occurred:

    import net.rim.blackberry.api.mail.*;
    import net.rim.blackberry.api.mail.event.*;
    import net.rim.device.api.system.*;
    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.component.*;

    public class MessageView extends Application implements ViewListener
    public static void main(String args[])
    MessageView theApp = new MessageView();

    public MessageView()
    Session ses = Session.getDefaultInstance();
    } catch (Exception e)

    public void open(MessageEvent e) {
    notifyUser("Message has been opened!");

    public void close(MessageEvent e) {
    notifyUser("Message has been closed!");

    //Get an instance of the UiEngine and place a Dialog in the queue
    //to alert the user of new message arrival.
    public void notifyUser(String data)
    UiEngine ui = Ui.getUiEngine();
    Screen screen = new Dialog(Dialog.D_OK, data, Dialog.OK, Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION), Manager.VERTICAL_SCROLL);
    ui.queueStatus(screen, 1, true);

    Users Online
    Currently online: 28 members 1,043 guests
    Please welcome our newest community members: