How to close a dialog box?

Hello

I displays a dialog with a Yes and no

UiApplication.getUiApplication().invokeAndWait( new Runnable() {

    public void run() {
       int response = Dialog.ask( Dialog.D_YES_NO, "Do you want to continue?" );

        // waits here for user interaction

        if ( response == Dialog.YES ) {
            // do the task         } else {
            // cancel the task         }
       }
   } );

The application must move forward with the task after 5 seconds if the user does not choose an option. I got this by creating a task of the timer as the dialog box is displayed, and when the timer expires I continue with the task.

The problem is that the dialog box, although that is no longer displayed, still waiting for user interaction. Is there a way to get the dialog box to complete or is there something else I can use that timeout?

And others who could do the job.  I like this, because it is self-contained.

I'm not sure that the code is self-explanatory, please ask if something is not clear.

Note that I have NOT tested, but I'm doing something similar, so I suspect it should work.  If you have any problems, I'll test and repair (if I can).

UiApplication.getUiApplication().invokeAndWait( new Runnable() {
    public void run() {
       final Dialog d = new Dialog("Do you want to continue?",
                                   new String [] { "Yes", "No" },
                                   new int [] { Dialog.YES, Dialog.NO },
                                   Dialog.YES,
                                   Bitmap.getPredefinedBitmap(Bitmap.QUESTION));
       Thread timerThread = new Thread() {
           public void run() {
               while ( !d.isDisplayed() ) {
                   try {
                       sleep(1000);
                   } catch (Exception e) {
                   }
               }
               // Above might be needed to make sure we won't start 5 sec wait
               // until the Dialog is actually displayed
               try {
                   sleep(5000);
               } catch (Exception e) {
               }
               if ( d.isDisplayed() ) {
                   // Dialog has not been automatically dismissed
                   // Automatically select YES
                   d.select(Dialog.YES);
               }
            }
        };
        timerThread.start();
        d.doModal();
        // Dialog will be forced close after 5 seconds by timerThread
        int response = d.getSelectedValue();
        if ( response == Dialog.YES ) {
            // do the task         } else {
            // cancel the task         }
       }
   }
);

Tags: BlackBerry Developers

Similar Questions

  • How to close the dialog box after pressing the button

    Hello. I added the button

    ButtonWidget

    (

    kButtonWidgetID,

    kSysButtonPMRsrcId,

    kBindNone,

    334, 434, 16, 16 + 24,

    kTrue, kTrue,

    kButtonLabelKey,

    ),

    and in my method in the file... Observer.cpp

    If (theChange is kTrueStateMessage)

    If (theSelectedWidget is kButtonWidgetID)

    This I want close dialogue

    How? I don't want to create CancelButtonWidget. It is must be cutom button.

    Try this in your dialogObserver,

    InterfacePtr myParent (this, UseDefaultIID());

    InterfacePtr ((IDialog*) myParent-> QueryParentFor (IID_IDIALOG)); dialog

    If the dialog box (dialogue)-> Close();

  • How to close this dialog box modal blocking and open a new one after a few minutes

    It's my method to display a modal dialog box:

    public static dialogue handleInactivityDialog (String msg, int [] values) {}
    Diálogo dialog = new dialog box (msg, new String() {"Yes", "No"}, values, 2, null);
    int i = dialogo.doModal ();
    If (I == 1) {}
    try {}
    do something
    Utils.popScreenForLogout ();
    } catch (Exception e) {}
    Utils.forceLogout ();
    }
    }
    return of diálogo;

    }

    After 3 minutes, this dialogue must be closed and should be opened a new. The new dialog box must be closed after 1 minute.

    I have no idea on how to do as DIalog.doModal () is a blocking operation.

    Thanks in advance!

    You can start a timertask before calling doModal, for example.

  • How to create modal dialog box with image

    I have this very simple modal dialog box:
    public class DialogPanels
    {
    
        public void initClosemainAppDialog(final Stage primaryStage)
        {
    
            primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>()
            {
                @Override
                public void handle(WindowEvent event)
                {
                    event.consume(); // Do nothing on close request
    
                    // Dialog Stage init
                    final Stage dialog = new Stage();
                    // If you want to freeze the background during dialog appearence set Modality.APPLICATION_MODAL
                    // or to allow clicking on the mainstage components set Modality.NONE
                    // and set dialog.showAndWait();
                    dialog.initModality(Modality.APPLICATION_MODAL);
                    dialog.initOwner(primaryStage);
    
                    // Frage - Label
                    Label label = new Label("Exit from the program");
    
                    // Button "Yes"
                    Button okBtn = new Button("Yes");
                    okBtn.setOnAction(new EventHandler<ActionEvent>()
                    {
                        @Override
                        public void handle(ActionEvent event)
                        {
                            //primaryStage.close();
                            //dialog.close();
                            //Platform.exit();    
                            System.exit(0);
                        }
                    });
    
                    // Button "No"
                    Button cancelBtn = new Button("No");
                    cancelBtn.setOnAction(new EventHandler<ActionEvent>()
                    {
                        @Override
                        public void handle(ActionEvent event)
                        {
                            primaryStage.show();
                            dialog.close();
                        }
                    });
    
                    // Layout for the Button
                    HBox hbox = new HBox();
                    hbox.setSpacing(10);
                    hbox.setAlignment(Pos.CENTER);
                    hbox.getChildren().add(okBtn);
                    hbox.getChildren().add(cancelBtn);
    
                    // Layout for the Label and hBox
                    VBox vbox = new VBox();
                    vbox.setAlignment(Pos.CENTER);
                    vbox.setSpacing(10);
                    vbox.getChildren().add(label);
                    vbox.getChildren().add(hbox);
    
                    // Stage
                    Scene scene = new Scene(vbox, 450, 150, Color.WHITESMOKE);
                    dialog.setScene(scene);
                    dialog.show();
                }
            });
    
        }
    }
    I want to add images and make to look like this:



    But I admin that it's too complex for my short knowledge get the appropriate result. Can you show me how I can split dialog box, add second bottom and make my code to look the same as this example please?

    I think that you can accomplish what you want by wrapping your 'vbox' VBox in an another VBox... Let's call it outerVBox. In outerVBox, you put a node ImageView and 'vbox'. To create the node ImageView (for example):

    Image bkgrdImage = new Image(getClass().getResourceAsStream("resources/my_pic.jpg"));
    ImageView bkgrdImageView = new ImageView(bkgrdImage);
    

    And then add nodes to outerVBox:

    outerVBox.getChildren().addAll(bkgrdImageView, vbox);
    

    (And of course to create the scene instance using outerVBox instead of "vbox.")

  • How do to the dialog box options spelling? (e-mail)

    Using windows mail. When I use the spellchecker, I get a "this language is no longer for the spell check. "Please select another in the dialog box options spelling" message. How do to the dialog box options spelling?

    This language is no longer available for spell checking. Please select another in the Spelling Options dialog.
     

    Change it back.
     

    1. in the main window of Windows Mail, click Tools
    2. the options
    3 spelling
    4. choose a language except English
    5. apply
    6. choose English
    7. apply
     
     
  • How to align the dialog box in the center of a popup programmatically

    Hey,.

    I use jdeveloper 11g release 2.

    Can someone help on how to align the dialog box programmatically a popup?

    Kind regards

    Steve

    Hello

    As far as I know, if we do not have indications of the dialog then displays on the center of the screen by default.

    This will solve your problem?

    Gud luck!

    HA

  • How to resize the dialog box that runs everything in baGetFolder order.

    Dear friends

    I'm very new Director and in collaboration for the project which is already developed by some other providers. in this project, I have to implement the mentioned below requirment so someone can pls help me on this will be greatfull.

    How to resize the dialog box that appears while baGetfolder command triggers. Actualluy problem that I face is that the title of the dialog box extends its width so the title turns out to be incomplete with «...» ", how can I solve this problem? It's very urgent requirment and eagely waiting for your response.

    Thanks in advance

    So how about:

    gBackPath = baGetFolder("/", "Veuillez sélectionner un répertoire de
    sauvegarde pour les fichiers de votre base de données: ", 1, "", 100, 50)
    

    (Note that the parameter 'options' has been changed to 1)

  • How to make a dialog box for a user to choose a file to disk

    Hello

    Is it possible to make a dialog box for a user of photoshop, choose a txt, process of my javascript file?

    I have a txt file with all the names and locations of the psd files, I want to treat by photoshop. I have e.g. 100 out of a folder with 250 images.

    If anyone has a shot "sample code" how to select a file - I will be happy.

    / T

    Here is an example of selection of a text file...

    var dlg=
    "dialog{text:'Script Interface',bounds:[100,100,500,220],"+
    "testFile:EditText{bounds:[10,40,310,60] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
    "Browse:Button{bounds:[320,40,390,61] , text:'<<' },"+
    "statictext0:StaticText{bounds:[10,10,240,27] , text:'Please select Text File' ,properties:{scrolling:undefined,multiline:undefined}},"+
    "Process:Button{bounds:[10,80,190,101] , text:'Process' },"+
    "button2:Button{bounds:[210,80,390,101] , text:'Cancel' }};"
    var win = new Window(dlg,'test');
    win.center();
    win.testFile.enabled=false;
    win.Browse.onClick = function() {
     selectedFile = File.openDialog("Please select TEXT file.","TEXT File:*.txt");
      if(selectedFile != null) win.testFile.text =  decodeURI(selectedFile.fsName);
    }
    win.Process.onClick = function() {
     if(win.testFile.text == '') {
      alert("No text file has been selected!");
      return;
      }
     win.close(1);
     selectedFile.execute();
    }
    win.show();
    
  • How to make the dialog box "New bookmark" Auto name and the location of the current page?

    I would like to add bookmarks by clicking on the right or on the bar inside a folder of bookmarks or bookmarks, and choosing "new bookmark". This opens a dialog box with the various areas. In the past, the fields title and location were auto-remplies using the title info and the location of the page / tab active. Now, however, all of the fields are empty, making it virtually impossible to use. How do I bring back this feature?

    I am running Firefox 40.0.2 for Windows, and I have the extension classic restaurateur theme installed. I have already looked at all options Classic theme restaurateur and haven't seen anything that would change/conflict with the behavior of bookmark Add.

    Try:

  • How to create a dialog box with a counter visible timeout?

    I have a dialog box which may arise when nobody is on the screen.  I would like to display a countdown in the dialog box that allows the operator knows that there so many seconds to make a decision before the program goes forward.  Is there a way to make the dialog box update while it is displayed?  What I have to do a sub VI or y at - it an easier way?  Any suggestions?

    To the best of my knowledge, you will not be able to change the construction in the dialog boxes to display a timer.  Maybe it's actually possible, but I doubt it's easy.

    In my opinion, you need to use a Subvi and display the front panel when it is called.  Organize the façade visually resemble the dialog box should appear with a digital indicator.  Feed the Subvi timeout value (which will allow you to decide when exit the while loop).  Use the "number of cycles (ms)" both inside and outside the while loop.  On the outside will mark the time during which the Subvi has been called.  Subtracting the two will change in time (how long the Subvi has worked in ms).  You can subtract this figure from the value of timeout and this thread to the digital indicator.  This will give you the effect of a countdown.

    If this value is less than zero, exit the while loop.  Similarly, if the operator performs certain tasks, exit the while loop.  On a side note, you can add a button to stop the countdown.  This will be useful if the operator gets to the screen with 2 seconds left.

  • How to call windows dialog boxes

    Hello

    I just want to know how to call a windows dialog box, I called below the dialog using VB script and the script is the following lol = msgbox ("Your Message here", 19, "Your title here") and save it as a .vbs file, by changing the number "19" in the script to generate the different dialog box. And I think it is called by the user32.dl of windows.

    So can you please help me to call the dialog even in labview.

    Thank you & best regards

    Samuel J

    System engineer

    CAPTRONIC systems Pvt Ltd

    Bangalore, India.

    See attached VI calling MessageBoxA from user32.dll. Sorry for french labels, comments and the description...

  • How to remove the dialog box "print to file".

    Initially up to and subsequently, I get a dialog box titled 'Print to File' and invites me to enter a "output file name" How can I get rid of this box? No matter what I do, I keep coming back!

    Hi cups WI,

    ·         Since when are you facing this problem?

    ·         Have you checked the problem in safe mode?

    Check if the following might help.

    Step 1: Start the computer in safe mode and check the number.

    Step 2: In safe mode, delete the printer and spool driver files. To do this,

    a. Click Start, click my computer.

    b. navigate to the following locations and then delete all files and folders in the following two folders (where C: is the drive where Windows XP is installed):

    • C:\Windows\System32\Spool\Printers
    • C:\Windows\System32\Spool\Drivers\w32x86

    Report of the results.

  • How to stop the dialog box advertising formats 'Windows 10' to come on my Windows 7 computer - I don't want that!

    Hello world.

    I have Windows 7, which I am pretty happy with.  I don't want to upgrade to Windows 10 because I think that's worse than my old system and were particularly impressed by their general customer service and after-sales.

    However, whenever I log in, I get a dialog box 'update of Windows 10' to come.  Its really annoying and I want to stop it.

    Does anyone know how?  Thank you.

  • How to disable this dialog box by default on 'Storm' of 9530 Simulator

    Hello

    I'm programming with SDK 4.7 and I develop application which

    currently uses the simulator of the storm.

    When I click on the button and open the new screen I get this dialog box each time:

    How can I disable this dialog box?

    Thank you in advance.

    You eat not navigation, click.

    If it's a ButtonField causing the problem, you can rectify by specifying the CONSUME_CLICK style in your constructor.

    For other types of fields, the question varies. You want to substitute navigationClick().  If so, make sure you return 'true' If you use a click event.  Otherwise, the system will pick up the event q perform the default action, which is in this menu.

  • How to create a dialog box for an inner thread

    Hi all

    I am trying to create a thread in which I am trying to establish an http connection. But when there is an exception. I want to inform the user of the exception by pushing a dialogue or a modal screen. But the dialogue is not calling. Any body knows how to push the inner thread dialog box

    / public class GPRSChanlInf implements Runnable {}

    public static thread = null;

    public String getResponse (String url_final) {}

    thread = new Thread (this);
    thread. Start();
    Thread.Sleep (20);

    }

    public void run() {}
    InputStream is = null;
    OutputStream os = null;
    HttpConnection conn = null;

    try {}

    Conn = (HttpConnection) Connector.open (url_final, Connector.READ_WRITE, true);

    }

    catch (Exception e) {e.printStackTrace () ;}
    }

    Looks OK code, intervened you in the code to ensure that the dialog box is actually called?

    Also can you confirm that this code is executed by a UiApplication who has "enterEventDispatcher()."

Maybe you are looking for

  • Problem between the navigation pane/project pane

    I imported a 20 minute video in the browser. When I insert the video in the project pane to get one - only - frame size postage stamp. Cannot stretch yellow handles right-left to sink into a film strip several dimensions. Cannot edit the video in its

  • UC3843 fault

    UC3843 does not work in multisim, I get 1.53 output instead of 180v

  • Garmin Vector pedals USB ANT + in LabVIEW

    Hello I would like to read the data of the vector Garmin pedals in LabView. For this, I would use the Ant + Garmin USB Stick. I read a lot of similar topics in the Forum. But there was no real solution. Is there someone who works in the same topic or

  • How can I create list of permutations

    Hello world I need to create a 2D array that will contain all the permutations of an input of 1 d array, specifically, I have a table 1 d of the colored boxes and I want to return an array of 2D-color boxes.  It's too mathematical for me!  Is there a

  • Loss of user account settings

    Lost my user account settings. Now start up with very limited features and white blue screen with some icons. Need help to restore the original settings if you please.