Thursday, April 11, 2013

On change ObectChoiceField, change it relative ObjectChoiceField Value


Blackberry we use ObjectChoiceField this example demo for check one choice field value change then it will effect other relatively choice field. Like when you change country then it should be change state and it city. Please see in code that help full and save lot of time.

ocfCountry.setChangeListener(new FieldChangeListener() {
   
 public void fieldChanged(Field field, int context) {
  // TODO Auto-generated method stub
  //ObjectChoiceField test= (ObjectChoiceField)field;
    
  int curInx = ocfCountry.getSelectedIndex();
  if(previIndexOfCountry != curInx && lolPre != curInx){
   System.out.println("Change Call.."+curInx);
   stateArray = setStateFromCountry(countryArray[curInx]);
   ocfState.setChoices(stateArray);
   cityArray = setCityFromState(stateArray[0]);
   ocfCity.setChoices(cityArray);
   invalidate();
  }
  if(curInx==0){
   System.out.println("Change Call.."+curInx);
   stateArray = setStateFromCountry(countryArray[curInx]);
   ocfState.setChoices(stateArray);
   cityArray = setCityFromState(stateArray[0]);
   ocfCity.setChoices(cityArray);
   invalidate();
  } 
  lolPre = ocfCountry.getSelectedIndex();
 }
});

Hope it will save your development time.