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: 35
Registered: ‎03-08-2009
My Device: Not Specified
Accepted Solution

ObjectChoiceField.setChoice() - Screen Problem

Currently have tried the following to programmatically update the available choices in an ObjectChoiceField.  For testing, I build an arbitrary String[], then attempt to update the OCF using setChoices() the two ways noted below.  I'm able to update the values in the OCF (well append, but that's another story, maybe related), but when the dropdown is clicked to view the items, all subsequent items in the manager disappear.   If I scroll up or down focusing on them, they partially reappear.  Something else to note, when debugging, as I scroll up and down, again focusing on different items, a nullpointerexception is constantly thrown. The lines commented out are other steps I tried that did not change anything. Thanks for any assistance. 
Worker.getInstance().addToQueue(new Runnable() {
        public void run () {
        String sData[] = new String[9];
        for (int i = 1; i < sData.length; i++) {
                sData[i] = "." + i;
        }
        synchronized(UiApplication.getUiApplication().getAppEventLock()) {
                // objectSelectField.setChoices(null);
                objectSelectField.setChoices(sData);
        }
                               
        /*
        UiApplication.getUiApplication().invokeLater(new Runnable() {
                public void run() {
                        objectSelectField.setChoices(sData);
                        // objectSelectField.getManager().invalidate();
                }
        });
        */
        }
});

Developer
Posts: 35
Registered: ‎03-08-2009
My Device: Not Specified

Re: ObjectChoiceField.setChoice() - Screen Problem

Solved.  Had to do with the field not being able to "gracefully" handle a null value in the [] (see for-loop). 

Developer
Posts: 40
Registered: ‎09-08-2011
My Device: 8900
My Carrier: AIS

Re: ObjectChoiceField.setChoice() - Screen Problem

That for loop should start:

 

for (int i = 0   <---- *ZERO*, not 1

 

You're leaving the first array element at its default: null.