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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

New Contributor
Posts: 2
Registered: ‎03-10-2013
My Device: blackberry 9930
My Carrier: Not specifed
Accepted Solution

ChoiceFiled field change listener Event getting called



I have created one choicefield. and on field chagne listener i am showing dialog depending on condtion that balance is zero.

now my  problem is once dialog is shown then after that its showing dialog for every choice while i try to chagne the choice.

lets say on 3rd choice balance is zero then dialog is shown, on ok click of dialog 3rd selection is shwon in choice field.

Now when chagne the choice so i select the choice filed , and navigate throgh choice , then for every choice even if the balane is is greater than 0 for that choie still its showing dialog for zero balance.

please can you tell me the solution to check that old selected index 

How to check that choice selection is completed  Or this filed is under selection mode.




below is my code.


fDestination = new ObjectChoiceField("", spinnerArray, 0,Field.FIELD_LEFT) {
       protected void layout(int width, int height) {
      super.layout(fContext.getScreenWidth() / 3, 45);       setExtent(fContext.getScreenWidth() / 3, 45);




fDestination.setChangeListener(new FieldChangeListener() {

      public void fieldChanged(Field field, int context) {
          try {

                  int dest = fDestination.getSelectedIndex() - 1;
                   if (dest != -1 ) {

                         if(balanceArray[dest].equalsIgnoreCase("0")) {
                                  Dialog.inform(fContext.getLabel("Balance is 0. select another destination"));

          } catch (ArrayIndexOutOfBoundsException ex) {

     } catch (NullPointerException ex) {




Below are my screen shots.

when i select any option where balance is not zero there its working fine but 

once choie selected for which  balance 0 dialog is shown.Then for any choice its shwing same popup message ,



Zero Balance Dialog         choice Filed





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

Re: ChoiceField field change listener Event getting called

This question has been asked before and I have never had a very good answer.  In the past I used focuslisteners, and when the ChoiceField looses focus, then you check the value.  That works OK. 


But I had an idea when I reviewed your question.  The popup list you see is actually a popup screen.  Because it is displaying in front of your Field, it actually drives the onObscured() method and then drives the onExposed() method when the popup menu is removed.  So you can ignore changes while this is happening.  Then you only get the last change!  And it seems to work.  Here is some test code - it assumes you have the boolean variable


as a global variable to this code:


Now in fact, onExposed and onObscured will get called in other circumstances, so to make this code bullet proof, you should probably check that the Field is in focus.  But I think it will work as is too.


Hope it works for you.


	    String [] options = new String [] { "1", "2", "3", "4" };
	    final ObjectChoiceField test = new ObjectChoiceField("Test: ", options) {
	    	public void onExposed() {
	    		displayingChoices = false;
	    	public void onObscured() {
	    		displayingChoices = true;
	    test.setChangeListener(new FieldChangeListener() {
	        public void fieldChanged(Field field, int context) {
	        	if ( displayingChoices ) {
	        	Dialog.inform("Selected: " +test.getChoice(test.getSelectedIndex()));

 test is declared final just because it was easier. So this is not production code, it is just to demonstrate the idea.  Impement this in your own way. 

New Contributor
Posts: 2
Registered: ‎03-10-2013
My Device: blackberry 9930
My Carrier: Not specifed

Re: ChoiceField field change listener Event getting called

Hi Peter,  

Thanks a  ton .

This solutions worked awesome.


 , Thanks again.