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

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

On close of popup only proceed




         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)); 
                // Change some data and invalidate
                if (mm.read == false) {
                    mm.read = true;
                    unreadCount -= 1;
                    if (unreadCount < 0)
                        unreadCount = 0;
                    System.out.println("UNREADCOUNT =  " + unreadCount + " ******************* ");
                    inboxBtn.setText("Inbox " + unreadCount);
                System.out.println("CheckBox Complete");

    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"));
            add(new LabelField("Label "));
        public void fieldChanged(Field field, int context) { 
            if (field == okBtn)
        protected boolean keyChar(char key, int status, int time) { 
            if (Keypad.KEY_ESCAPE == key) { 
                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.






For any helpful answers give kudo's (star) to the helper.
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-, Z10 (STL100-3)-, Z30 (STA100-5)-, Passport (SQW100-1)-, PlayBook (16GB)-
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.
Trusted Contributor
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.