BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 05-21-2008, 06:12 AM   #1
ahmadgee
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: do not know
Posts: 51
Default close the popupscreen

Please Login to Remove!

Hi,
I used the method to close the screen in class extended by the PopupScreen

this.close();

against ok button event.

But got the illegalStateException error.

Thanks for any suggestion.
Offline  
Old 05-21-2008, 08:07 AM   #2
CELITE
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Default

If you are debugging the application in the IDE, you can get a more detailed message by peeking into the Exception object in the variable pane.
Offline  
Old 05-21-2008, 08:43 AM   #3
ahmadgee
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: do not know
Posts: 51
Default

Quote:
Originally Posted by CELITE View Post
If you are debugging the application in the IDE, you can get a more detailed message by peeking into the Exception object in the variable pane.
Thanks CELITE,
When I clicked on the Exception Thrown, the I got the follwoing details
super: java.lang.RuntimeException
super: java.lang.Exception
super: java.lang.Throwbale
super: java.lang.Object

Please tell me the method to close the popup screen.

Best regards,
Offline  
Old 05-21-2008, 08:58 AM   #4
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

how do you call the screens close method? my first guess would be from outside the event thread, invokelater would help.
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 05-21-2008, 09:29 AM   #5
CELITE
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Default

Quote:
Originally Posted by simon.hain View Post
how do you call the screens close method? my first guess would be from outside the event thread, invokelater would help.
I would guess that too.

Look at the throwable object. Inside that object is a message. What does it say?
Offline  
Old 05-21-2008, 09:44 AM   #6
ahmadgee
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: do not know
Posts: 51
Default

Quote:
Originally Posted by simon.hain View Post
how do you call the screens close method? my first guess would be from outside the event thread, invokelater would help.
Thank Simon, I applied invokeLater in the condition when user click on the ok button of popupscreen. And found the following response displayed in comments.

Code:
UiApplication.getUiApplication().invokeLater(new Runnable()
            {               
                public void run()
                {
                    onClose();//as this method exited from application
                    close();//this method gave me IllegalStateException
                }
             });
Best regards
Offline  
Old 05-21-2008, 10:25 AM   #7
ahmadgee
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: do not know
Posts: 51
Default

Quote:
Originally Posted by CELITE View Post
I would guess that too.

Look at the throwable object. Inside that object is a message. What does it say?
Thanks again CELITE
The message is

detailMessage:"Cannot mix queueStatus-dismissStatus with
pushGlobalScreen-popScreen".

I have also used the invokelater. But found the same message.

Best regards,
Offline  
Old 05-21-2008, 12:05 PM   #8
CELITE
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Default

Just call close()
If it still fails post the code showing how you display the screen.
Offline  
Old 05-23-2008, 02:52 AM   #9
ahmadgee
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: do not know
Posts: 51
Default

Quote:
Originally Posted by CELITE View Post
Just call close()
If it still fails post the code showing how you display the screen.
Thanks CELITE for your concentartion, My code is as follow.
Code:
class Test extends net.rim.device.api.ui.UiApplication 
{
    public static void main(String[] args)
    {
        Test instance = new Test();
        instance.enterEventDispatcher();
    }  
    public Test() 
    {
        pushScreen(new MyMainScreen());
    }
}
Code:
class MyMainScreen extends MainScreen implements FieldChangeListener
{
    ListField mainList = new ListField();    
    ListCallback mainCallback = new ListCallback();    
    ButtonField addButton;
    ButtonField removeButton;
    public MyMainScreen()
    {                
        String firstField = new String("aaa");
        String secondField = new String("bbb");
        mainList.setCallback(mainCallback);        
        mainList.insert(0);
        mainCallback.insert(firstField, 0);
        mainList.insert(1);
        mainCallback.insert(secondField, 1);
        this.add(mainList);        
        
        addButton = new ButtonField("Add");
        addButton.setChangeListener(this);
        add(addButton);
        
        removeButton = new ButtonField("Remove");
        removeButton.setChangeListener(this);
        add(removeButton);       
    }    
    
    public boolean onClose()
    {
        System.exit(0);
        return true;
    }
    
    ///////////////////List_elements_Listener///////////////////////////////////////
    
    public boolean trackwheelClick( int status, int time ) 
    {
        switch(mainList.getSelectedIndex())
        {
            case 0: 
                Dialog.alert("Show contents of aaa!"); 
                break;
            case 1: 
                Dialog.alert("Show contents of bbb"); 
                break;
        };
        return true;
    }
    
    //------------------------ListCallback class implementing ListFieldCallback
    public static class ListCallback implements ListFieldCallback
    {
        
     private Vector listElements = new Vector();

        public void drawListRow(ListField list, Graphics g, int index, int y, int w)
        {
            String text = (String)listElements.elementAt(index);
            g.drawText(text, 0, y, 0, w);
        }

        public Object get(ListField list, int index)
        {
            return listElements.elementAt(index);
        }

        public int indexOfList(ListField list, String p, int s)
        {
            return listElements.indexOf(p, s);
        }

        public int getPreferredWidth(ListField list)
        {
            return Graphics.getScreenWidth();
        }

        public void insert(String toInsert, int index)
        {
            listElements.addElement(toInsert);
        }

        public void erase()
        {
            listElements.removeAllElements();
            
        }
    }  
    
    ////////////////Button Event Listener handling//////////////////////////////////
 
    public void fieldChanged(Field field, int context)
    {
        if (field == addButton)
        {
            UiEngine ui=Ui.getUiEngine();
            ui.pushGlobalScreen(new MyPopscreen("Please enter "),1,true);
        }
        if (field == removeButton)
        {
            mainList.delete(mainList.getSelectedIndex());            
            Dialog.inform("Selected  item was removed successfully!");            
        }
    }    
}
Code:
public final class MyPopscreen extends PopupScreen implements FieldChangeListener {
    
    ButtonField okButton;
    ButtonField cancelButton;
    EditField   urlEditField;  
        
    public MyPopscreen(String question) {                
    super(new FlowFieldManager());        
    add(new RichTextField(question, NON_FOCUSABLE));
    urlEditField=new EditField("URL:","");
    add(urlEditField);          
    okButton = new ButtonField("Ok");
    okButton.setChangeListener(this);
    add(okButton);
        
    cancelButton = new ButtonField("Cancel");
    cancelButton.setChangeListener(this);
    add(cancelButton);       
    }
    
     public void fieldChanged(Field field, int context)
    {
        if (field == okButton)
        {
            int ind=0;
            String newFeed=null;
             add(new LabelField(urlEditField.getText()+" was added successfully"));
               
            UiApplication.getUiApplication().invokeLater(new Runnable()
            {                
             public void run()
              {
                   close();
               }
             });
        }
        
        
        if (field == cancelButton)
        {
            onClose();
         }
    }
        
    public void paint(Graphics graphics) {        
        graphics.clear();
        super.paint(graphics);
    }
    
    public boolean onClose() {
        System.exit(0);
        return true;
    }   
}
Best regards
Offline  
Old 05-23-2008, 09:26 AM   #10
CELITE
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Default

Ah I see now. Don't call pushGlobalScreen on your popup. Just call pushScreen instead.
Offline  
Old 05-23-2008, 09:45 AM   #11
ahmadgee
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: do not know
Posts: 51
Default

Thanks CELITE, I understood the error now.

Can you tell me please that how can I copy the value entered on popup screen into the main screen.

Best regards,
Offline  
Old 05-23-2008, 10:28 AM   #12
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

you have to create a callback and hand it to your popup screen.
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 05-24-2008, 06:52 PM   #13
CELITE
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Default

I'd go with simon's recommendation for sure. Use anonymous objects for your callbacks.

Another way is the true model view controller pattern where you have a singleton controller responsible for dispatching messages in an event queue.
Offline  
Old 05-26-2008, 02:53 AM   #14
ahmadgee
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: do not know
Posts: 51
Default

Can you please recommend me some material regarding to implementing this concept.

Thanks
Kind regards
Offline  
Old 05-26-2008, 03:53 AM   #15
ahmadgee
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: do not know
Posts: 51
Default

Before applying the concept on list, I am trying to apply the concept on EditField. But could not get the updated main screen. Can any body tell me where is wrong. Thanks


Code:
class PopupScreenCopyData1_MyMainScreen1 extends MainScreen implements FieldChangeListener
{
    ButtonField openButton;
    EditField eField;    
    PopupScreenCopyData1_MyMainScreen1() {                
        eField=new EditField();
        eField.setText("aaaa");
        add(eField);         
        openButton=new ButtonField("Open Popup");
        openButton.setChangeListener(this);
        add(openButton);      
   }
   
   public void fieldChanged(Field field, int context)
    {
        if (field == openButton)
        {
            UiEngine ui=Ui.getUiEngine();
            PopupScreenCopyData1_PopupScreen1 popscreen=new PopupScreenCopyData1_PopupScreen1();
            ui.pushScreen(popscreen);   
         }
    }
    public boolean onClose()
    {
        Dialog.alert("Bye World!");    
        System.exit(0);
        return true;
    }  
} 

final class PopupScreenCopyData1_PopupScreen1 extends PopupScreen implements FieldChangeListener
{
    ButtonField okButton;
    PopupScreenCopyData1_MyMainScreen1 main;
    PopupScreenCopyData1_PopupScreen1()
    {
        super(new FlowFieldManager());
        add(new EditField("Name",""));
        okButton=new ButtonField("OK");
        okButton.setChangeListener(this);
        add(okButton);
    }    
    public void fieldChanged(Field field, int context)
    {
        if (field == okButton)
        {
           
            UiApplication.getUiApplication().invokeLater(new Runnable()
            {
                public void run()
                {
                    main=new PopupScreenCopyData1_MyMainScreen1();
                    main.eField.setText("bbbb");                    
                    close();
                }
            }
            );                           
        }        
    }
   }
Offline  
Old 05-26-2008, 09:13 AM   #16
CELITE
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Default

The first thing I'm confused about is where you are setting the variable "main" in your popup class. The code you have below will cause null pointer exceptions.


Here's the callback pattern we were referring to:

Code:
// In new class file
public interface IScreenCallback {
    public void screenCallback( Object eventData );
}

// In your popupscreen class:
private IScreenCallback _callback;
public void setScreenCallback( IScreenCallback callback ) {
    _callback = callback;
}

public void fieldChanged( Field field, int context ) { // personally I would just anonymously implement 
    if ( field == okButton ) {                         // trackwheelClick on your button fields instead of using
        _callback.screenCallback( "bbbb" );            // fieldChangedListeners
    }
}

// In your mainscreen class:
public void fieldChanged( Field field, int context ) {
    if ( field == openButton ) {
        PopupScreenCopyData1_PopupScreen1 popupscreen = new PopupScreenCopyData1_PopupScreen1();
        popupscreen.setScreenCallback( new IScreenCallback() {
            public void screenCallback( Object eventData ) {
                eField.setText( eventData.toString() );
            }
        });
        UiApplication.getUiApplication().pushScreen( popupscreen );
    }
}
Offline  
Old 05-27-2008, 03:56 AM   #17
ahmadgee
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: do not know
Posts: 51
Default

Quote:
Originally Posted by CELITE View Post
I'd go with simon's recommendation for sure. Use anonymous objects for your callbacks.

Another way is the true model view controller pattern where you have a singleton controller responsible for dispatching messages in an event queue.
Thanks CELITE for your kind guideline, I performed using the model view controller pattern
Best Best regards,
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


Jelenko Commodore LS VPF with Pump  picture

Jelenko Commodore LS VPF with Pump

$875.00



Mitsubishi Control Board DM00N649.  SM76A127G02 . Ductless unit 47-0910KR (C64) picture

Mitsubishi Control Board DM00N649. SM76A127G02 . Ductless unit 47-0910KR (C64)

$120.00



Vintage Holt Commodore Commercial Floor Scrubber Polisher Buffer Burnisher picture

Vintage Holt Commodore Commercial Floor Scrubber Polisher Buffer Burnisher

$599.99



3D MULTIMEDIA VIDEO CARD C64/V2 1MB picture

3D MULTIMEDIA VIDEO CARD C64/V2 1MB

$94.05



Vintage Printer Switch box Commodore 64/Sanyo Mountable Computer PC picture

Vintage Printer Switch box Commodore 64/Sanyo Mountable Computer PC

$49.00



POLAR PLASTICS C64 Construction Film,6x100,4Mil,Clear PK 4 picture

POLAR PLASTICS C64 Construction Film,6x100,4Mil,Clear PK 4

$178.04







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