Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Trusted Contributor
trupti
Posts: 242
Registered: ‎03-16-2010
My Device: 9530
Accepted Solution

On close of popup only proceed

 

Hello,

 

         In my fieldChanged(), I call a popup message. The popup has a Close button that closes the popup. I don't want the app to do any work until the popup is not closed. I am not able to achieve it. The code is :

 

    public void fieldChanged(Field f, int context) {
        System.out.println("Into ------------ BUTTON CLICKED = " + f + " C0NTEXT = " + context + " btnClicked = " + btnClicked);
        if (f instanceof CheckboxField) {
            CheckboxField cb = (CheckboxField) f;
            // Get details associated with the selected checkbox
            UiApplication.getUiApplication().invokeAndWait(new Runnable() {
                    public void run() {
                        getScreen().getUiEngine().pushScreen(new MessagePopup(mm1)); 
                        return;
                    }
                });
                // Change some data and invalidate
                if (mm.read == false) {
                    mm.read = true;
                    cb.setCookie(mm);
                    unreadCount -= 1;
                    if (unreadCount < 0)
                        unreadCount = 0;
                    System.out.println("UNREADCOUNT =  " + unreadCount + " ******************* ");
                    inboxBtn.setText("Inbox " + unreadCount);
                    invalidate();
                }
                System.out.println("CheckBox Complete");
             }
        }

   // POPUP CLASS
    class MessagePopup extends PopupScreen  implements FieldChangeListener  {
        private BitmapButtonField okBtn;
        
        public MessagePopup(MailMessage mm) { 
            super(new VerticalFieldManager(VERTICAL_SCROLL | VERTICAL_SCROLLBAR));
            okBtn = new BitmapButtonField(Bitmap.getBitmapResource("res/cancel_btn.png"));
            okBtn.setChangeListener(this);
            add(new LabelField("Label "));
            add(okBtn);
        }
        
        public void fieldChanged(Field field, int context) { 
            if (field == okBtn)
                this.close(); 
        } 
        
        protected boolean keyChar(char key, int status, int time) { 
            if (Keypad.KEY_ESCAPE == key) { 
                this.close(); 
                return true; 
            } else 
                return super.keyChar(key, status, time); 
        } 
    }

 

 

The output is: popup is shown and I see the following SOP's

CheckboxField Selected********** READ = false****
UNREADCOUNT = 4 *******************

CheckBox Complete

 

According to me, when I click Ok button in the popup then the below 2 lines i.e.

UNREADCOUNT = 4 *******************

CheckBox Complete

 

should be executed.

 

Any idea how do I work out with this scenario. Any help is highly appreciative.

 

 

Thanks

 

 


--------------------------------------------------------------------------------
For any helpful answers give kudo's (star) to the helper.
Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.2174, Z10 (STL100-3)-10.3.0.700 Dev OS, Z30 (STA100-5)-10.3.0.700 Dev OS, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: On close of popup only proceed

If I understand correctly, you don't want "if(mm.read == false)" to get executed until the screen closes?

 

If that is correct then replace "pushScreen" with "pushModalScreen". Modal screens block until the screen closes. You don't need to an invokeAndWait operation since the modal screen will block execution anyway.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
Trusted Contributor
trupti
Posts: 242
Registered: ‎03-16-2010
My Device: 9530

Re: On close of popup only proceed

 

Thanks rcmania, you are right Modal screens blocks further execution till it is closed.

 

Once again Thanks a lot.


--------------------------------------------------------------------------------
For any helpful answers give kudo's (star) to the helper.
Please use plain text.