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
Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: Credentials Screen: Extend PopupScreen or Dialog?

 


RexDoug wrote:

I think you are making this about 3x more complicated than necessary.

 

The best advice I've got was about 5 posts ago Smiley Happy

 

1. Create your screen class (for a first cut, how about just extending MainScreen?  It's easier)

2. Add your input fields

3. Add your buttons (Submit and Cancel) with listener

4. Add your "handler" methods (onSubmit and onCancel)

5. Look for your butttons in the listener, and dispatch to the correct handler

 

...and you are done (at least, with the UI portion).

 

 

 

 

 

 


Couple things:
I'm trying to extend PopupScreen or Dialog because I need a Dialog and, according to the API docs, I should extend Dialog or PopupScreen to do so.  I'm confused as to why you keep suggesting I extend MainScreen instead...would it be easier to create a Dialog this way?
Not sure if you saw my response to your post 5 posts back but just in case...I can construct the UI just fine with PopupScreen or Dialog...it's getting the button values when clicked that I'm having issues with. 

 

 

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Credentials Screen: Extend PopupScreen or Dialog?

[ Edited ]

I'm confused as to why you keep suggesting I extend MainScreen

 

Err...I only suggested it once.  Smiley Happy

 

Why do you need to get the values? The button is pressed, your handler for the button invokes some action (like kicking off your HTTP, or whatever). This is event-driven UI programming.

 

If you insist on forcing this into a procedural model, then I guess you would:

 

1. store a value for the result, like 0=submit, -1=cancel

2. retreive the value using a getter, like getResult()

3. push the screen modally (your popup would have to dismiss itself in this case, after pressing any button)

4. Retreive the value using the getter

5. do whatever

 

If you haven't already done so, I think you could benefit from working through the sample programs that ship with the JDE.

 

 

 

 

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Credentials Screen: Extend PopupScreen or Dialog?

Looking at your previous post - this code won't do what you want:

 

public static int ask()

{

UiApplication.getUiApplication().pushScreen(this);

return getSelectedValue();

}

 The "return" statement will be executed as soon as the screen is pushed, so the selectedValue() will be incorrect.

 

I think this is what you want:

 

public static int ask()

{

UiApplication.getUiApplication().pushModalScreen(this);

return getSelectedValue();

}

 

The screen has to be modal so that your "return" statement will not execute until the screen is dismissed. Also note that your button handlers will have to (a) set the value, and (b) pop the screen.

 

Highlighted
Developer
Posts: 16,750
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Credentials Screen: Extend PopupScreen or Dialog?

another option would be a DialogClosedListener.

Dialog is just a pre-implemented  popupscreen. If you really want you can add/insert fields on a dialog.

----------------------------------------------------------
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: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Credentials Screen: Extend PopupScreen or Dialog?

Good suggestion.

 

Developer
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: Credentials Screen: Extend PopupScreen or Dialog?

 


RexDoug wrote:

I'm confused as to why you keep suggesting I extend MainScreen

 

Err...I only suggested it once.  Smiley Happy

 

Why do you need to get the values? The button is pressed, your handler for the button invokes some action (like kicking off your HTTP, or whatever). This is event-driven UI programming.

 

If you insist on forcing this into a procedural model, then I guess you would:

 

1. store a value for the result, like 0=submit, -1=cancel

2. retreive the value using a getter, like getResult()

3. push the screen modally (your popup would have to dismiss itself in this case, after pressing any button)

4. Retreive the value using the getter

5. do whatever

 

If you haven't already done so, I think you could benefit from working through the sample programs that ship with the JDE.

 

 

 

 


Actually I have gone through a number of the JDE sample programs.
I think either I may be misunderstanding you or vice versa.  by "get button values" I mean how do I...or do I need to implement a handler for buttons I didn't create...aka the standard Dialog button options (D_OK_CANCEL, D_YES_NO, etc)?  I'm extending the Dialog class to create a D_OK_CANCEL Dialog with a username and password field and what I'm trying to do is implement a handler...if it's possible...for the OK and CANCEL buttons.
I don't want to store a value, I dont' need to store a value...I just want to implement a handler that will work with the standard D_OK_CANCEL buttons.

 

 

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

Re: Credentials Screen: Extend PopupScreen or Dialog?

each button in a dialog represents a value. If you use a standard D_OK_CANCEL dialog you get two buttons, one with the value of Dialog.CANCEL and one with Dialog.D_OK (both a static int values from the Dialog class).

 

If you use the dialog as a blocking part in your app, for example by using Dialog.ask, you get an int value back that refers to the pressed key. see the API for more details.

 

The dialogclosedlistener gets the same value, you can use it to continue execution in your application. (google callback)

 

If you use an extended Dialog constructor you can specify the values for the buttons.

----------------------------------------------------------
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: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: Credentials Screen: Extend PopupScreen or Dialog?

 


simon_hain wrote:

each button in a dialog represents a value. If you use a standard D_OK_CANCEL dialog you get two buttons, one with the value of Dialog.CANCEL and one with Dialog.D_OK (both a static int values from the Dialog class).

 

If you use the dialog as a blocking part in your app, for example by using Dialog.ask, you get an int value back that refers to the pressed key. see the API for more details.

 

The dialogclosedlistener gets the same value, you can use it to continue execution in your application. (google callback)

 

If you use an extended Dialog constructor you can specify the values for the buttons.


 

 

Thanks for the info. 

I suspected as much when reading the API, but the code I wrote previously to run based on Dialog.D_OK and Dialog.CANCEL didn't work.  I'll go back to it again...I probably missed something.

 

Also, did you mean Dialog.OK instead of Dialog.D_OK?

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

Re: Credentials Screen: Extend PopupScreen or Dialog?

probably. you can post your code and we can try to fix it.

----------------------------------------------------------
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: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: Credentials Screen: Extend PopupScreen or Dialog?

 


simon_hain wrote:

probably. you can post your code and we can try to fix it.


 

 

That's ok.  I'll work on it myself for a bit to see if I can get to run correctly first.

If I'm desperate I'll post back. 

 

Thanks for the info and the help