Dialog.Ask

How to use it

public static int ask(String message,                      Object[] choices,                      int defaultChoice)

any psudo code

    public void a(){

        UiApplication.getUiApplication().invokeLater(new Runnable(){
            public void run(){

                Object[] choices = new Object[] {"cancel", "exit", "to background" };
                int result = Dialog.ask("really quit?", choices, 1);

                switch (result) {
                case 1:
                System.exit(0);
                case 2:
                UiApplication.getApplication().requestBackground();
                }
            }});
    }

Tags: BlackBerry Developers

Similar Questions

  • I get a dialog asking me if I want to open or save a document in firefox, whenever I click on an email in outlook in windows; What can I do to fix this? Thank you.

    Question
    I get a dialog asking me if I want to open or save a document in firefox, whenever I click on an email in outlook in windows; What can I do to fix this? Thank you

    Is it through Outlook Web Access?

  • Dialog.ask () do not work?

    Hi all

    I called Dialog.ask (Dialog.D_YES_NO, "text") in class A that extern class Thread.

    I debuged and he ran on this line but the dialog box occur and my program is suspended.

    but Dialog.ask (Dialog.D_YES_NO, "text") work well when she called in the class screen extern class.

    No matter what suggesstion, thank you!

    I think that you must synchronize the lock of the event when calling Dialog.ask

    public class A extends Thread{
        public void run(){
            ...
            synchronized(UiApplication.getEventLock()){
                 Dialog.ask(...);
            }
            ...
        }
    
    }
    
  • Need help Dialog.Ask

    Hello

    How can I get the value of the button clicked the dialog.ask that I tried with the following code, but it is retruning-1.

    Here is the code I tried

    result int = Dialog.ask (Dialog.D_YES_NO, "you do not have an open account, you want to create a?");    . Can someone help me with the code snippet.

    Thank you

    Sujithravindran

    follow these steps:

    Dialog d = new Dialog(Dialog.D_YES_NO,
                            "You don't have an Account open, would you like to create one?",
                            1,
                            null,
                            Manager.USE_ALL_WIDTH);
                    int i = d.doModal();
    
                    if (i == Dialog .YES)
                    {
                        //do something positive ehre
                    }
                    else
                    {
                           //do something ehre
                    }
    
  • Call Dialog.ask in the Thread Run method

    "in I want to call Dialog.alert and using following code but its exception to throw the wire.

    "Exception occurs java.lang.RuntimeException: pushModalScreen called by a thread of non-event."

    synchronized (Application.getEventLock ())

    {

    if (Dialog.ask ("catalog is obsolete. You want to keep it? ", choices, select, select [0])(==1)"

    {

    Run the required functionality

    }

    }

    pls help me

    I keep saying this, so forgive me of repeating myself, but:

    synchronized (Application.getEventLock ()) {}

    should only be used when nothing else will work for you or you make a very simple, very fast UI update.

    A Dialog.ask is not very fast!

    In this case, you have several options, but the most obvious solution is to ask the question before starting the Thread.  So, if that is your treatment

    Thread catUpdateThread = new Thread() {}

    public void run() {}

    Dialog.ask (...)

    Other treatments

    }

    }

    catUpdateThread.start ();

    What should do the same and works OK. :

    UiApplication.getUiApplication.invokelater (new Runnable() {}

    public void run() {}

    Dialog.ask (...)

    If (result == Yes) {}

    Thread catUpdateThread =...;

    catUpdateThread... Start();

    }

    }

    });

  • Retrieve the value of Dialog.ask

    I am trying to write a function that will create a context menu using Dialog.ask and return the result of the dialog box to the calling Thread.  So far I have somethings like this:

    //display a pop-up "Yes or No" box and return true for yes, false for no
    public boolean ask(final String question){
        UiApplication.getUiApplication().invokeLater (new Runnable(){
                                                          public void run(){
                                                              int answer = Dialog.ask(Dialog.D_YES_NO, question, Dialog.NO);
                                                              if(answer == Dialog.YES){
                                                                  //somehow return true                                                          }
                                                              else{
                                                                  //somehow return false                                                          }
                                                       }});
    }
    

    I've seen a similar thread, but I didn't know how to use the solution.

    http://supportforums.BlackBerry.com/T5/Java-development/getting-values-back-from-runnable-dialog-ask...

    In short, how to use DialogClosedListener to retrieve the value of Dialog.ask to ?

    First of all, you probably want to use invokeAndWait so that the calling thread is blocked until the Runnable.run () ends. After that, one solution is to store the result of somewhere. For example, the subclass of the floor and add a field where you store the value (a more general concept of an executable that can return a value in J2SE is the future, but it is not available out of the box in J2ME). Once completed invokeAndWait, you can read this field. Alternatively, you may return the value by changing something in the outer class (one that contstructs the Runnable). For example,.

    final int[] result = new int[1];
    UiApplication.getUiApplication().invokeAndWait(new Runnable() {
      public void run() {
        result[0] = Dialog.ask(...);
      }
    });
    
    int choice = result[0];
    ...
    
  • Does anyone know how to change the culmination of auto from 'no' to 'yes' in dialog.ask?

    No big deal here, I want to just my 'Yes' button, highlighted initially instead of the 'no' in the dialog.ask function. Anyone know how to change it? Thank you!

    Something like that?

    int choice = Dialog.ask (Dialog.D_YES_NO, "You want to stop downloading?", Dialog.NO);

  • Retrieve the values of the executable (Dialog.Ask)

    Hello world!

    I have a situation where I have to ask the user a question according to the status of a remote object (sent to a web service).  This operation is performed within a Thread, so I can't directly use the Dialog.Ask () because it translates into the exception "Engine UI consulted without holding the lock of the event".  I used this code sample to get the dialog to the user

            synchronized(UiApplication.getEventLock()) {            Runnable push = new Runnable() {
    
                    public void run() {                    Dialog.ask(message, choices, 0);                }
    
                };
    
                UiApplication.getUiApplication().invokeLater(push);        }
    

    This work is nice, but I can't retrieve the result... And because it's in a thread, I don't know how I could get it... Can someone help me with this one?

    Thank you!

    You usually use

    Synchronized (UiApplication.getEventLock ())

    or

    UiApplication.getUiApplication (.invokeLater)

    There's no value in using both at the same time.

    In this case, the Dialog.ask returns an int, that indicates the result.  The doc of the API:

    Returns:
    The selection of your choice (not the index) value, as must be returned by getSelectedValue(). For example, CANCEL, OK or DELETE are among the possible return values.

    Thus, you can code something like:

    int i = Dialog.ask (...);

    Treat the i then returned.

    Without doubt, you actually want to return the result in your calling Thread.  I don't know how "legal", it is, but you might be able to get away with:

    selectedChoice int = - 1;

    {Synchronized (UiApplication.getEventLock ())}
    selectedChoice = Dialog.ask (.);

    }

    If you can't do that, then look to split the treatment at the time of questions and using a DialogClosedListener to the decision of the user process.  I don't know there are other options, just of can't think right now.

  • Previous button doesn't work is not in dialog.ask

    Hello

    If dialog.ask with 2-3 buttons is displayed on clickin device key return her without closing the dialog box, but dialog.alert is closed

    How to close the dialog box?

    Use constructor [] [] and the values of the choices and add values to activate the BACK-1 button.

  • Use Dialog.ask to call message (email/sms)

    Hello

    I try to use Dialog.ask to ask the user to send information by e-mail or sms... I use the following code:

    public void ask(){
    
          UiApplication.getUiApplication().invokeLater(new Runnable(){          public void run(){
    
                  Object[] choices = new Object[] {"Email", "SMS",};                int result = Dialog.ask("Send Via:", choices, 1);
    
                   switch (result) {             case 1:               email();              case 2:               sms();                    }};       });   }
    

    When I use the dialog box displayed correctly, however when I choose either by e-mail or sms nothing happens...

    I'm fairly new to java and mobile development so easy on me... I'm sure it's a simple solution.

    I have searched these forums and tried a few different things, cant just make it work the way I need to.

    Incase anyone wants to see these:

    public void email(){      MessageArguments messageArgs = new MessageArguments(MessageArguments.ARG_NEW, "","", messageField.getText());        Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, messageArgs);   }
    
        public void sms(){        MessageArguments messageArgs = new MessageArguments(MessageArguments.ARG_NEW_SMS);        Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, messageArgs);        
    
        } 
    

    Thank you so much for your support and your help

    Thanks for the suggestion of using the breaks.  I have inserted two breaks and I'm still questions... See code below.  Again, any suggestions are welcome!

    public void ask(){
    
          UiApplication.getUiApplication().invokeLater(new Runnable(){          public void run(){
    
                  Object[] choices = new Object[] {"SMS", "Email"};             int result = Dialog.ask("Send Via:", choices, 1);
    
                   switch (result) {             case 1:                   sms();                    break;                case 2:                   email();                  break;            }};       });   }
    

    In doing so, the top option, SMS, still does not.  The button at the bottom, email, will work as it should

  • Prevent a Dialog.ask beeing scrolled down on the launch

    Hello!

    I want to show a EULA (very long chain) in a Dialog.ask, but it scrolls down to the buttons when it is released. Is there a simple way to avoid that I can't find?

    Thank you!

    only focusable components allow to scroll.

    I had a similar problem while displaying a EULA. on top, it was very long, and the formatting is complex.

    I opted for the EULA, including in html format.

    in my UI I show accept, refuse, and display buttons.

    show the button opens the html code in the browser - with all the formatting done automatically.

    nobody reads the EULA anyway, and let the user scroll through miles of text if it does not intend to read is bad design.

  • Detect leak in Dialog.ask

    How can I detect the ESC on a Dialog.ask?

    At the closing of the application, I ask the user if they want to whether it is running in the background. Answering questions works very well. However, for convenience, I hit the ESC key to be the same by selecting Cancel.

    I know I should be able to understand this one. But I give up. Help?

    public MyScreen() {
        super(Manager.NO_VERTICAL_SCROLL);
    
        ...
    }
    public boolean onClose() {
        if (stuff is running) {
            int q = Dialog.ask(
                "Keep running in the background?",
                new String[]{"Yes","No","Cancel"},
                new int[]{1,0,2},
                1
            );
            if( q == 1 ) {
                theApp.requestBackground();
            } else if( q == 0 ) {
                System.exit(0);
            } else {
                //nevermind
            }
        } else {
            System.exit(0);
        }
        return false;
    }
    

    Add '-1' to your list of accepted options.»

  • Dialog.Ask in another language

    Hello... I´d like to know if there is any chance of a dialogue, ask (dialog.ask), but with the text of the button in the (spanish) language one another. Instead of YES, SO it would be so IF NOT :-D Thank you!

    http://www.BlackBerry.com/developers/docs/4.7.0api/NET/rim/device/API/UI/component/dialog.html#dialo... (java.lang.String, java.lang.Object [], int [], int, net.rim.device.api.system.Bitmap)

  • Print button to print the page 10 to the dialog asking the user how many times to print page 10

    Hi all

    Want javascript to attach to a button that does the following: -.

    ask the user in the dialog box how many copies of page 10, they wish to print.

    Seems easy hmmm not to me... Unfortunately.

    If this cannot be done is is it possible to have page 10 selected in the dialog box for normal printing on a button... which brings up the print dialog box and all you have to do is select the number of copies.

    Thanks in advance

    Stephen

    You can use this code to do this:

    var copies = Number(app.response("How many times do you want to print page 10?","",""));
    if (!isNaN(copies) && copies>0) {
        var pp = this.getPrintParams();
        pp.firstPage = 9;
        pp.lastPage = 9;
        pp.NumCopies = copies;
        this.print(pp);
    }
    
  • Stop dialog ask for update iOS

    Hi, I have a mini iPad 4 and it will open a dialogue frequently to ask to install the new version of iOS... I don't want to... The options are: Yes... Or later...  I'll go crazy... Maybe I'll throw it to the floor again. Thank you!

    Remove the downloaded iOS (settings - general - use - Storage manage)

    It crashes download iOS on your router (add mesu.apple.com to a list of blocked sites). Or disable WiFi while your iPad is in charge.

Maybe you are looking for

  • Calibration of pressure sensor

    I have two pressure omegadyne transducers. I tried to calibrate the transducers via linear equations. The problem is that when I put the second slope of line transducer and the y-intercept, the first (slope of the line and intercept) changes automati

  • Vista SP2 fails to install error 0 x 80070005

    Here are the results of accesschk: HKLM\software\Microsoft\Windows\CurrentVersion\Component Servicing\Retry Agent of base HKLM\software\Microsoft\Windows\CurrentVersion\Component base Servicing\Sqm HKLM\software\Microsoft\Windows\CurrentVersion\Compo

  • Ethernet/LAN works do not, XP Pro OS

    for some reason my LAN is not working, I currently use a dongle broadband mobile to do this. I can't find anywhere, LAN not in Device Manager or anywhere else. its got my 1394 connection, but not the LAN, my pc is a compaq presario SR5019uk btw, I kn

  • wireless network icon has disappeared from the State system and the notification bar

    wireless network icon disappeared from the tray system and notifications (that is to say, it is no longer a wireless icon by the clock where I can see networks, connect to the network, or see the strength of the network).  How to bring back icon?

  • printers and internal hard drive

    We have a Dell all-in-one (AIO) printer 962 and we wish to dispose of it.   Until we do that, however, we would like to ensure you that don't contain any of our private information.  We wondered if this printer was an internal hard drive.  If so, whe