BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 09-18-2007, 07:06 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Get rid of dialog?

Please Login to Remove!

I have a dialog like this opened:
Code:
int cancel = Dialog.ask("synchronizing...", new String[] {"Cancel"}, new int  []   {Dialog.CANCEL}, Dialog.CANCEL);
When the "Cancel" button of the dialog is clicked everything is ok, but when it is not clicked I would like to move the dialog out of my application. How can i get that?
Offline  
Old 09-19-2007, 08:37 AM   #2 (permalink)
New Member
 
Join Date: Sep 2007
Model: 7100
PIN: N/A
Carrier: Vodafone
Posts: 10
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

In theory you should be able to create an instance of Dialog:

Code:
Dialog dialog = new Dialog( "synchronising...", new String[] { "Cancel" }, new int[] { Dialog.CANCEL }, Dialog.CANCEL, Bitmap.getPredefinedBitmap(0) );
dialog.doModal();
and then use the .close() or .cancel() method to dismiss it but when I simulate some external event by passing the dialog to another thread and invoking either method I get:

Code:
java.lang.IllegalStateException
Offline  
Old 09-19-2007, 09:49 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, I tried that idea. I make my own dialog box and push it to the display, like this:
Code:
cancelDialog = new CancelDialog("synchronizing...", new String[] {"Cancel"},
        new int[] {Dialog.CANCEL}, Dialog.CANCEL, Bitmap.getPredefinedBitmap(Bitmap.INFORMATION));
    UiApplication.getUiApplication().pushGlobalScreen(cancelDialog, 0, UiEngine.GLOBAL_MODAL);
..but when I want to close it, nothing happens, doesn't throw an exception even. I used several ways to close it.

1)
Code:
    cancelDialog.cancel();
    cancelDialog.close();
    UiApplication.getUiApplication().repaint();
2)
Code:
    UiApplication.getUiApplication().popScreen(cancelDialog);
...or something like this. I have no idea what is wrong.
Offline  
Old 09-24-2007, 01:41 AM   #4 (permalink)
Talking BlackBerry Encyclopedia
 
Skipper_Joe's Avatar
 
Join Date: Jan 2007
Location: Kharkov, Ukraine
Model: 8300
Carrier: N/A
Posts: 237
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

1) You need to close Dialog from another thread, since doModal() or ask() methods block current thread.

2) Since you close dialog from outside UI event-handling thread, you need to use something like this:
Code:
_uiApplication.invokeLater(new Runnable()
{
    public void run()
    {
        _dialog.close();
    }
});
Offline  
Old 09-24-2007, 03:35 AM   #5 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
    cancelDialog = new CancelDialog("Synchronizing...", new String[] {"Cancel"},
        new int[] {Dialog.CANCEL}, Dialog.CANCEL, Bitmap.getPredefinedBitmap(Bitmap.INFORMATION));
    UiApplication.getUiApplication().pushModalScreen(cancelDialog);
......and trying to close it
Code:
UiApplication.getUiApplication().invokeLater(new Runnable(){
            public void run() {
              cancelDialog.cancel();
              cancelDialog.close();
              updateLayout();
            }
          });
Well it is not working that way , but thank you for the advice!
Offline  
Old 09-24-2007, 05:45 AM   #6 (permalink)
Talking BlackBerry Encyclopedia
 
Skipper_Joe's Avatar
 
Join Date: Jan 2007
Location: Kharkov, Ukraine
Model: 8300
Carrier: N/A
Posts: 237
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Do you call second piece - with invokeLater() - from other thread?
Offline  
Old 09-24-2007, 09:44 AM   #7 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I called these two pieces in the main thread. Firstly I have opened the dialog, then started another thread (it makes some things) and at the end i closed the second thread and i wanted to close the dialog box that is displayed to the screen while the second thread is working. At the end of the second thread I am again in the main thread and want to close the dialog programatically, not as clicking the trackwheel.
Offline  




Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.