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
Highlighted
Contributor
Posts: 38
Registered: ‎03-13-2012
My Device: 9860
My Carrier: 1234
Accepted Solution

Return a value from Popup Screen

[ Edited ]

Long story short - I have a PopupScreen. This has two textboxes. What I want to do is call a method on the origional screen (the one that calls the popup), using these two text box values.

 

The only thing I cant seem to do is pass back the two field values. Ive tried calling the method. Even tried passing the screen into the popupscreens constructor. 

 

 

private class goToMenuItem extends MenuItem {
        public goToMenuItem() {
            super( new StringProvider( "Test" ), 0, 0 );
        }
        public void run() {       
        	CustomPopUpScreen cstmScreen = new CustomPopUpScreen();
        	UiApplication.getUiApplication().pushModalScreen(cstmScreen); 
        }  
     }

 

 

	public class CustomPopUpScreen extends PopupScreen {
	    	
	        BasicEditField T1;
	        BasicEditField T2;
	        
	        public CustomPopUpScreen() {	        	
	            super(new VerticalFieldManager(CustomPopUpScreen.NO_HORIZONTAL_SCROLL));

	            BasicEditField T1= new BasicEditField( "T1: ", "", 20, BasicEditField.EDITABLE | BasicEditField.FILTER_REAL_NUMERIC);
	            BasicEditField T2= new BasicEditField( "T2: ", "", 20, BasicEditField.EDITABLE | BasicEditField.FILTER_REAL_NUMERIC);
	                  
	            ButtonField cancel = new ButtonField("Cancel");
	            ButtonField submit = new ButtonField("Go To");
	            add( T1);
	            add( T2);
	            add(submit);
	            add(cancel);
	            
	            
	            
	            cancel.setChangeListener( new FieldChangeListener() {
	    			public void fieldChanged(Field arg0, int arg1) {			
	    				close();
	    			}
	    		});
	            
	            submit.setChangeListener( new FieldChangeListener() {
	    			public void fieldChanged(Field arg0, int arg1) {	
	    				GoTo();
	    				close();
	    			}
	    		});
	        }
	        
	        public void GoTo()
	        {
	                //GoTo(Double.parseDouble(T1.getText()),Double.parseDouble(T2.getText()));	        	     
	        }
	    }

 

Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Return a value from Popup Screen

you can use a callback pattern to do that. google it if you don't know how it works.

you can take a look at http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/ui/component/Dialog.html with its separate mechanisms, it has the ask method that returns a value, as well as a DialogClosedListener which is a callback.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Return a value from Popup Screen

[ Edited ]

Just adding a little to Simon's answer.

 

"What I want to do is call a method on the original screen "

 

OK, I have to ask, why do you want to do this?  it doesn't sound very Object ish.

 

If you want to call this method once the screen has been closed, then the approach you are using (modal screen) will work, you need to get the values within the menu processing, and then you can invoke the processing from within the menu processing in the Screen which has access to the method. 

Contributor
Posts: 38
Registered: ‎03-13-2012
My Device: 9860
My Carrier: 1234

Re: Return a value from Popup Screen

The Dialog.ask that you suggested doesnt appear to be what I want.

 

That is just a warning box (or what ever you specifiy it to), that shows a message, and gives differnt buttons to click as a response.

 

At no point can you actually enter into a string field as none exist on it.

 

 

Using my origional idea I passed in the main screen to the constructor of the popup screen, so I can still call back methods on the main screen then call close().

 

Its probably not the correct way of doing.

 

A popupbox where they could type in a string or two, and it gets returned, like a method would - would be ideal.

Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Return a value from Popup Screen

passing the screen reference is ok, it is usually encapsulated in an interface (which also allows to implement the interface anonymously).

i did not suggest that you use dialog, only that you look at the mechanisms it uses.

another option for you is, as you push the popup as a modal screen, to ask the screen for it's value in the line below pushModal.
pushModal returns after the screen is popped, and at this time it has the value you need, so you can call a getValue method.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter