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

Posts: 813
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Change objectchoicefield based on another

Vector vof = new Vector();
		int iSetTo = 0;
		   final String choices11[] = new String[vof.size()];
	        final String choices12[] = new String[vof.size()];
	        for(int i = 0; i<vof.size() ;i++)
	        	Language mo = (Language) vof.elementAt(i);
	        	choices11[i] =  mo.nameEng;
	        	choices12[i] = ""+mo.id;
	        final ObjectChoiceField maf = new ObjectChoiceField("Sub Category",choices11,iSetTo);
		   Vector vo = new Vector();
		   final String choices[] = new String[vo.size()];
	        final String choices2[] = new String[vo.size()];
	        for(int i = 0; i<vo.size() ;i++)
	        	Language mo = (Language) vo.elementAt(i);
	        	choices[i] =  mo.nameEng;
	        	choices2[i] = ""+mo.id;
	        final ObjectChoiceField ma = new ObjectChoiceField("Category",choices,iSetTo);



I want on change of first objectchoicefield, to change the second objectchociefield w ith new data i bring from database. any helps?

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

Re: Change objectchoicefield based on another

You can do this in the FieldChangedListener.


However be aware that for ObjectChoiceField, a new fieldChanged is generated whenever the user changes it and you might therefore get a load of requests.  In addition, since you are touching the database which might be quite slow, you should probably do the request for data asynchronously, otherwise you are blocking the Event Thread.  As a result, you might consider just doing this in onUnfocus for the first ObjectChoiceField, or onFocus for the second ObjectChoiceField.  The trouble with these two is that then nothing happens to the second ObjectChoiceField as the first one is changed.


Another option is to load up the possible values into memory, and then you don't need to worry about making an asynchronous call and you can do it in fieldChanged().  An in memory selection process will tie up the UI briefly, but not enough to worry about blocking the Event Thread. 


In summary,

1) you can use a FieldChangeListener or Focus change to trigger the update of the second Field

2) If you are using an SQL database to select the elements for the second Field, then I would be careful about the processing that you do in these Listeners to make sure that you do not block the Event Thread.