Welcome!

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

Listen for a dialog closed event

by Retired ‎02-16-2010 01:24 PM - edited ‎09-16-2010 02:44 PM (1,979 Views)

Summary

 

This article applies to the following:

  • BlackBerry® Java® Development Environment (BlackBerry JDE)
  • BlackBerry smartphones based on Java technology

Procedure

 

You can create a DialogClosedListener by implementing the net.rim.device.api.ui.component.DialogClosedListener interface and customizing it to suit your needs. A DialogClosedListener provides one method (dialogClosed) that is invoked when the specified Dialog object is closed.The following example shows how to implement a DialogClosedListener that invokes your application logic when the Dialog object is closed:

 

 

/**
* MainApp
*/
package DialogListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.Screen;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.system.Bitmap;
public class MainApp extends UiApplication
{
        private MainScreen mainScreen;

        public static void main(String[] args) {
            MainApp theApp = new MainApp();
            theApp.enterEventDispatcher();
        }
        public MainApp() {
            mainScreen = new MainScreen();
            LabelField title = new LabelField("DialogClosedListener Example",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
            mainScreen.setTitle(title);

            //Display the main screen
            pushScreen(mainScreen);

            //Create Bitmap and MyDialogClosedListener instance
            Bitmap oBitmap = Bitmap.getPredefinedBitmap(Bitmap.INFORMATION);
            MyDialogClosedListener oMyDialogClosedListener = new MyDialogClosedListener();
            //Initialize the Dialog object
Dialog dialog = new Dialog(Dialog.D_OK_CANCEL,"DialogClosedListener-Test",1,oBitmap,Field.FOCUSABLE | Field.FIELD_HCENTER);

            //Assign a DialogClosedListener to the Dialog object
dialog.setDialogClosedListener(oMyDialogClosedListener);

            //Show the dialog
            dialog.show();
        }
}
/**
* MyDialogClosedListener
*/
package DialogListener;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.DialogClosedListener;
public class MyDialogClosedListener implements DialogClosedListener {
    public MyDialogClosedListener() { }
    
    public void dialogClosed(Dialog dialog, int choice) {
        
        //Put your on dialog closed logic here.
        System.out.println("Dialog Closed: " + choice);

    }
}

 

Contributors
Users Online
Currently online: 35 members 1,034 guests
Please welcome our newest community members: