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: 275
Registered: ‎03-10-2009
My Device: Not Specified

how to find out when selection has been made on ObjectChoiceField

Hello,

 

I have an ObjectChoiceFIeld and I wish to call a function whenever a selection has been made in said Field. I have tried using FieldChangeListener and onUnfocus to no avail. Using FieldChangeListener the function is called when a selection has been made AND when the user moves focus from one selection to the other. using onUnfocus nothing happens. can someone tell me what the correct way to do this is?

 

also, something weird is going on. my app is a regular UiApplication app, but for some reason it starts up automatically when the simulator starts. No I do not have Auto-start enabled in the application descriptor.

 

Thanks a lot!

Developer
Posts: 23
Registered: ‎12-21-2009
My Device: 8800
My Carrier: Zain

Re: how to find out when selection has been made on ObjectChoiceField

use FocusChangeListener

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to find out when selection has been made on ObjectChoiceField

I use FieldChangeListener.  Yes it gets called more often than really needed, but is that a bad thing?

 

I don't understand what you mean by "it starts up automatically".  How does this manifest itself?

Developer
Posts: 275
Registered: ‎03-10-2009
My Device: Not Specified

Re: how to find out when selection has been made on ObjectChoiceField

hi thanks for your reply. I just tried doing what you said and still no luck. I think it is failing because currently that is the only field I have on my screen, thus it always has focus. 

 

any more ideas? also, any thoughts on my second question?

 

thanks

Developer
Posts: 275
Registered: ‎03-10-2009
My Device: Not Specified

Re: how to find out when selection has been made on ObjectChoiceField

 


peter_strange wrote:

I use FieldChangeListener.  Yes it gets called more often than really needed, but is that a bad thing?

 

I don't understand what you mean by "it starts up automatically".  How does this manifest itself?


 

 

Hi Peter,

 

But it is a bad thing, because that's not the behavior I wanted. I only want the function to be called when the user has made a selection, not while the user is selectING. so i guess my question is how do I tell the function to only run when the user has selectED and not while he is still selectING. 

 

regarding my second question, I am quite baffled too as I have never seen this behavior. here's what happens:

 

1. I hit Run in Eclipse and things run normally.

2. Simulator loads, Home screen is shown, and all of a sudden my app's screen is pushed. At this point I have not pressed any button or scrolled any trackball. 

 

thank you! appreciate your help!

Developer
Posts: 94
Registered: ‎10-01-2009
My Device: Not Specified

Re: how to find out when selection has been made on ObjectChoiceField

Just because a function gets called doesn't mean it has to actually do anything.

 

It's pretty normal to have a listener determine the state of what it's listening to and decide from that what it needs to do.  Or not do.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to find out when selection has been made on ObjectChoiceField

I'm not convinced it is a bad thing.  You see the same behavior when typing in an EditField. You could argue that the Field Changed Listener should not be called until the user has finished but it is actually called for each input character.

 

Anyway, I thought I had a work around for you.  onExposed for the ObjectChoiceField is called when the popup collapses.  Try this:

 

ObjectChoiceField ocf = new ObjectChoiceField(" ",new String[]{"some", "text"}) {
    protected void onExposed() {
        System.out.println("onExposed");
    }
};

 

However,, onExposed will be called whenever another screen covers up the OCF, such as a menu. 

 

But the big killer is the Space Bar.  If you use the Space Bar, the selection is changed without displaying the popup choices.  So I think you are stuck with using FieldChanged and processing every selection.

 

Re your second problem, what level of Component Pack are you using.  I remember that someone suggested to assist in testing applications would be immediately invoked - if you have a recent version perhaps they have done it?!  But I really have no other idea.  Sorry.

Developer
Posts: 94
Registered: ‎10-01-2009
My Device: Not Specified

Re: how to find out when selection has been made on ObjectChoiceField

Something else to check on the autostart thing: The "Run Configurations..." and "Debug Configurations..." menu items open a configuation dialog.  The "Simulator" tab of the dialog has a field labeled "Launch app or URL on startup:". See if there is something in that field.  Maybe they implemented the feature Peter talked about by putting the current project there as a default.

 

In my previous post I forgot to actually answer the question of "how to tell the function when to run".  I'm not sure I'm qualified anyway: for instance, I have absolutely no clue what ChoiceField.CONTEXT_CHANGE_OPTION means.  But if I were doing it, first thing I'd do is get the sequence of states by walking through a selection with breakpoints or println statements, looking for some unique condition the function could use to decide when to do something.  Track changes in the selection index, that sort of thing.

Developer
Posts: 275
Registered: ‎03-10-2009
My Device: Not Specified

Re: how to find out when selection has been made on ObjectChoiceField

 


peter_strange wrote:

I'm not convinced it is a bad thing.  You see the same behavior when typing in an EditField. You could argue that the Field Changed Listener should not be called until the user has finished but it is actually called for each input character.

 


 

hey Peter, thanks again for your reply. the behavior you described is fine with me as well, however I still want to only run a specific code when a selection has been made. For example, I want to display a Dialog with the alert "Selection made" when a selection has actually been made, and not when the user is still selecting. based on your described behavior, this Dialog will popup every time a user scrolls up or down a row. so this goes back to my first question, how do I tell if a selection has been made and finalized on the ObjectChoiceField?

 

Highlighted
Developer
Posts: 275
Registered: ‎03-10-2009
My Device: Not Specified

Re: how to find out when selection has been made on ObjectChoiceField

 


jMarc wrote:

Something else to check on the autostart thing: The "Run Configurations..." and "Debug Configurations..." menu items open a configuation dialog.  The "Simulator" tab of the dialog has a field labeled "Launch app or URL on startup:". See if there is something in that field.  Maybe they implemented the feature Peter talked about by putting the current project there as a default.

 

In my previous post I forgot to actually answer the question of "how to tell the function when to run".  I'm not sure I'm qualified anyway: for instance, I have absolutely no clue what ChoiceField.CONTEXT_CHANGE_OPTION means.  But if I were doing it, first thing I'd do is get the sequence of states by walking through a selection with breakpoints or println statements, looking for some unique condition the function could use to decide when to do something.  Track changes in the selection index, that sort of thing.


 

i think thats it!! thanks a lot! maybe this is a new feature on the latest Eclipse plugin? ive recently installed the new plugin so thats probably why. thanks a lot!