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
New Developer
Posts: 5
Registered: ‎08-24-2009
My Device: Not Specified
Accepted Solution

ChoiceField FieldChangeEvent

I have a ChoiceField field and when a user selects a different choice, I want to go and get data for that choice. But when I am scrolling through the list of choices, the event is raised everytime. I only want to get the data when the user selects a new choice. cField.toString() is the last selected value.

 

For example:

 

Select Color:  Red

 

Options are Red, Blue, Green, Orange.

 

The code below will be called 3 times when I am moving from Red to Blue to Green to Orange.

 

private FieldChangeListener CreateFieldChangeListenerEventHandler() { FieldChangeListener changeListener = new FieldChangeListener() { /* (non-Javadoc) * @see net.rim.device.api.ui.FieldChangeListener#fieldChanged(net.rim.device.api.ui.Field, int) */ public void fieldChanged(Field field, int context) { ChoiceField cField = (ChoiceField)field; // Data is always called when traversing through the list of choices. // getData(cField.toString()); } }; return changeListener; }

 

What am I missing?

 

 

Developer
Posts: 905
Registered: ‎02-07-2009
My Device: BlackBerry Torch 9800
My Carrier: Globe Telecom

Re: ChoiceField FieldChangeEvent

that's the default behavior. in order for you to just get the selected one, use the getChoice();

 

String yourChoice = cField.getChoice(cField.getSelectedIndex()); 

New Developer
Posts: 5
Registered: ‎08-24-2009
My Device: Not Specified

Re: ChoiceField FieldChangeEvent

Ok thanks for that.

 

But even if I use getChoice() instead of toString(), this method will still be called everytime I move from one option to the next by the event handler. Is there something (like a flag?) that I can use so that getData will be called when the user selects Orange (menu disappears and the screen shows Orange).

 

I tried to use isDirty, isMuddy but both are always true. IsSelecting was then next choice but IsSelectable is false for ChoiceFields.

 

 

Developer
Posts: 905
Registered: ‎02-07-2009
My Device: BlackBerry Torch 9800
My Carrier: Globe Telecom

Re: ChoiceField FieldChangeEvent

just to be clear, so what you want to do is that, when the user selects an item in your choice field, that's the only time your application will retrieve the data of that selected item, did i get that right? 

 

if that's the case, you can use the trackWheelclick or navigationClick to capture that the user selected an item. then from there, you can invoke the getChoice(getSelectedIndex).

 

Highlighted
New Developer
Posts: 5
Registered: ‎08-24-2009
My Device: Not Specified

Re: ChoiceField FieldChangeEvent

Ok I've figured it out. I ended up using the context parameter to see what caused the event to be fired. Although there doesn't seem to be any documentation as to what the integer values correspond to.

 

 

private FieldChangeListener CreateFieldChangeListenerEventHandler() { FieldChangeListener changeListener = new FieldChangeListener() { /* (non-Javadoc) * @see net.rim.device.api.ui.FieldChangeListener#fieldChanged(net.rim.device.api.ui.Field, int) */ public void fieldChanged(Field field, int context) { if(context == 0) { return; } ChoiceField cField = (ChoiceField)field; Dialog.alert(cField.getChoice(cField.getSelectedIndex()).toString()); } }; return changeListener; }