BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-21-2009, 10:52 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2009
Model: 8300
PIN: N/A
Carrier: Rogers
Posts: 43
Post Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy new Dialog() hides dialog box behind screen? :(

Please Login to Remove!

Hey all,

I am new to BB development. I would like to add a simple dialog box to the screen. Here is my code :

ITRequests.java
Code:
import net.rim.device.api.ui.*;

class ITRequests extends UiApplication {
    
    public static void main(String[] args){       
       ITRequests myApp = new ITRequests();
       myApp.enterEventDispatcher();
    }
    
    ITRequests() {
        HomeScreen homeScreen = new HomeScreen();
        this.pushScreen(homeScreen);
    }
}

HomeScreen.java
Code:
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;    // for Dialog class
import net.rim.device.api.system.Bitmap;     // for bitmaps

class HomeScreen extends MainScreen {
    private Dialog statusDlg;
    
    public HomeScreen() {
        super();
        // set the title
        this.setTitle("IT Requests");
        // create a dialog box to notify the user of the tickets being downloaded
        Bitmap icon = Bitmap.getBitmapResource("img/download.png"); 
        statusDlg = new Dialog("Downloading Info...",null,null,0,icon);
        statusDlg.show();
    }
The code compiles and runs fine. However, when I run the app, the first thing I see is a blank screen (with the title set to "IT Requests").

There is no diablog box visible. I was hoping there would be. If I click the back button on my blackberry, then it goes to a blank screen (with no title) and the dialog box appears.

What did i do wrong? I'd like it to appear right away when the app starts (on the same screen as the title).

Thanks!!

Ryan
Offline  
Old 07-21-2009, 12:20 PM   #2 (permalink)
New Member
 
Join Date: Jul 2009
Model: 9500
PIN: N/A
Carrier: student
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

i am not sure,but try this.add(statusDlg);
Offline  
Old 07-21-2009, 12:22 PM   #3 (permalink)
New Member
 
Join Date: Jul 2009
Model: 8300
PIN: N/A
Carrier: VZ
Posts: 13
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

What I do is the following (I'd love to hear it is someone has a better approach).

PHP Code:

// within my screen constructor
_contentArea = new VerticalFieldManager(Manager.VERTICAL_SCROLL Manager.VERTICAL_SCROLLBAR Manager.USE_ALL_HEIGHT);
this.add(_contentArea);

        
(new 
Thread(new PopulateScreen())).start(); 
Then have a thread populate the screen (making sure to get the latch on the drawing context)

PHP Code:
                // inside my inner class PopulateScreen which implements Runnable
        
public void run()
        {
            
pushWorkingDialog();


                        
//  Load whatever objects you want here - 
                        //  i.e. make any network requests outside of the
                        // UI event lock

                        
synchronized(UiApplication.getUiApplication().getEventLock()) {
                        
                         
_contentArea.add/*whatever widgets you want*/ );
                    
                         
_contentArea.invalidate();// make sure your changes get painted.

            
}
            

            
popWorkingDialog();
        }


        private 
void pushWorkingDialog()
        {
            
synchronized(UiApplication.getUiApplication().getEventLock()) {
                
_workingPopup = new WorkingPopupScreen(" Please wait... ");
                
RemoteApp.getInstance().pushScreen(_workingPopup);
            }
        }
        
        private 
void popWorkingDialog()
        {
            
synchronized(UiApplication.getUiApplication().getEventLock()) {                
                
RemoteApp.getInstance().popScreen(_workingPopup);
            }
        }
        private 
WorkingPopupScreen _workingPopup
Where WorkingPopupScreen is just my customization of a PopupScreen.
Offline  
Old 07-21-2009, 03:32 PM   #4 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2009
Model: 8300
PIN: N/A
Carrier: Rogers
Posts: 43
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Arg, this is so frustrating. Thanks to the people that have tried to help me so far. I still can't get it working.

I have spent 2 days (yes 2 days) on this. I'm guessing my dialog box gets created, then the "HomeScreen" gets created over top of it so you don't see the dialog box.

Is that correct?

how do I make the dialog box appear at the top of the screen stack?

thanks!
Offline  
Old 07-21-2009, 05:15 PM   #5 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

You can't push a screen from within the constructor of another screen and expect it to appear *above* the screen. Your dialog is getting pushed first, then your screen.

Anyway, why are you doing this? If you were really downloading something in this constructor, it would cause the BB OS to abort your app with an "app not responsive" message.

The downloading has to happen in another thread. If this were for real, you would implement some type of Observer mechanism in your UI so that the communications thread notifies your UI of progress.

Try this (for grins): add a MenuItem, and show the status dialog when the menu item is selected. Then it will show *above" the screen.
Offline  
Old 07-22-2009, 07:41 AM   #6 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2009
Model: 8300
PIN: N/A
Carrier: Rogers
Posts: 43
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank for the reply

That makes sense. What I'd like to happy is my constuctor start a new thread (that downloads some data). The new thread adds a new dialog that says "Please wait". When the download is complete the dialog is removed.

I added the new dialog at the beginning of the new thread.... it didn't appear there either. I'm guessing it's because the constructor called the new thread and added the dialog before the constuctor finished and added the main screen (so the dialog is behind).

Is that correct? When/how should i be adding the please wait dialog?

thx!
Offline  
Old 07-22-2009, 08:15 AM   #7 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

You can only interact with the UI from within the UI thread. You cannot directly access the UI from another thread that you start from the UI thread.

The correct sequence of events:
Implement a callback or listener (Observer/Observable) in the background thread
Implement the listener for this in your UI class
Start the thread
Put up a dialog, modal
The background thread notifies the UI when something interesting happens

From the listener implementation in the UI, you will do something to the UI using invokeLater() ((like pop the dilaog). This places the UI operation IN THE EVENT THREAD.

Last edited by Dougsg38p : 07-22-2009 at 08:16 AM.
Offline  
Old 08-16-2009, 03:49 AM   #8 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2009
Model: 8120
PIN: N/A
Carrier: gmail
Posts: 18
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

instead of statusDlg.show() plz try UiApplication.getUiApplication().pushGlobalScreen( statusDlg , 1, true);
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





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