BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 07-21-2009, 10:52 AM   #1
RyanRitten
Knows Where the Search Button Is
 
Join Date: Jun 2009
Model: 8300
PIN: N/A
Carrier: Rogers
Posts: 43
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
vandzi
New Member
 
Join Date: Jul 2009
Model: 9500
PIN: N/A
Carrier: student
Posts: 2
Default

i am not sure,but try this.add(statusDlg);
Offline  
Old 07-21-2009, 12:22 PM   #3
DeveloperDave
New Member
 
Join Date: Jul 2009
Model: 8300
PIN: N/A
Carrier: VZ
Posts: 13
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
RyanRitten
Knows Where the Search Button Is
 
Join Date: Jun 2009
Model: 8300
PIN: N/A
Carrier: Rogers
Posts: 43
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
Dougsg38p
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
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
RyanRitten
Knows Where the Search Button Is
 
Join Date: Jun 2009
Model: 8300
PIN: N/A
Carrier: Rogers
Posts: 43
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
Dougsg38p
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
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
abhiyenta
Knows Where the Search Button Is
 
Join Date: Mar 2009
Model: 8120
PIN: N/A
Carrier: gmail
Posts: 18
Default

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



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Single To 3 Phase 7.5KW 10HP 220V Variable Frequency Drive Inverter CNC VFD VSD picture

Single To 3 Phase 7.5KW 10HP 220V Variable Frequency Drive Inverter CNC VFD VSD

$169.90



VEVOR 7.5KW 10HP Variable Frequency Drive Inverter Convert 1 To 3 Phase VFD 220V picture

VEVOR 7.5KW 10HP Variable Frequency Drive Inverter Convert 1 To 3 Phase VFD 220V

$163.99



VEVOR 3HP 2.2KW 10A Variable Frequency Drive VFD for 3-Phase Motor Speed Control picture

VEVOR 3HP 2.2KW 10A Variable Frequency Drive VFD for 3-Phase Motor Speed Control

$79.99



VEVOR 4KW 220V 5HP Variable Frequency Drive Converter VFD Inverter 1 To 3 Phase picture

VEVOR 4KW 220V 5HP Variable Frequency Drive Converter VFD Inverter 1 To 3 Phase

$124.99



VFD Variable Frequency Drive 1 or 3 Phase input 0-400HZ 5.5kW 7.5HP 220V 25A picture

VFD Variable Frequency Drive 1 or 3 Phase input 0-400HZ 5.5kW 7.5HP 220V 25A

$175.00



750W 1HP 220V Variable Frequency Drive Inverter Converter Single To 3 Phase VFD picture

750W 1HP 220V Variable Frequency Drive Inverter Converter Single To 3 Phase VFD

$34.99







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