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 Contributor
divyeshk
Posts: 6
Registered: ‎05-24-2012
My Device: Curve -8520
My Carrier: Airtel
Accepted Solution

open objectChoiceField on press of enter , curve 8520 (JDE 5.0)

Hi,

 

I have added objectChoiceField on horizontalfieldManager (hfm ),  and hfm is added to main vericalfieldmanager.

 

which i click on trackpad , my objectChoiceField opens and i am able to do the selection,

but when i press enter (when ojectchoicefield is focused ), focus moves to next field. I want to open choicefield when i press enter on focus choicefield.

 

Thanks in advance.

 

Thanks and Regards,

Divyesh

 

Please use plain text.
Developer
crispyoz
Posts: 223
Registered: ‎10-01-2011
My Device: Bold 9900

Re: open objectChoiceField on press of enter , curve 8520 (JDE 5.0)

I had a similar issue, I decided to override  keyDown on the screen to capture the enter key and inject the required event if the field is focused.

Please use plain text.
Developer
peter_strange
Posts: 19,598
Registered: ‎07-14-2008
My Device: Not Specified

Re: open objectChoiceField on press of enter , curve 8520 (JDE 5.0)

Rather than inject an event, which if course requires permission, you might be able to just invoke navigationClick.  Give it a try.

Please use plain text.
Developer
crispyoz
Posts: 223
Registered: ‎10-01-2011
My Device: Bold 9900

Re: open objectChoiceField on press of enter , curve 8520 (JDE 5.0)

Yes that is a fair point, however personally I have an issue with calling event handlers directly, it's just a bad habit to get into and can be a slippery slope.


Please use plain text.
Developer
peter_strange
Posts: 19,598
Registered: ‎07-14-2008
My Device: Not Specified

Re: open objectChoiceField on press of enter , curve 8520 (JDE 5.0)

Personal preference perhaps, but I'd rather than not inject events.  In addition to permissions, there are potential timing issues. 

 

As an alternative, in your keyChar method, you might be able to call super and pass a 'SPACE' rather than an 'ENTER' to super....  From memory, I think space will cause the Field to expand.  Still theoretically calling an event handler, but at least it is an expected call, just not with the expected data....

 

Actually it might be ALT not SPACE.  Sorry can't test....

Please use plain text.
New Contributor
divyeshk
Posts: 6
Registered: ‎05-24-2012
My Device: Curve -8520
My Carrier: Airtel

Re: open objectChoiceField on press of enter , curve 8520 (JDE 5.0)

thanks for your responses.

 

1) navigationClick - > I debugged the behaviour and found that navigationclick is being called when trackpad is clicked. to implement same behaviour I tried overriding keychar method of mainscreen and called

super.navigationClick(status, time); , but no luck. :smileysad:

 

2) ALT button - yeah, I can see the dropdown list expanded when i press Alt +down click , but i want choicefield to be expanded on click of enter (as per blackberry UI and navigations guidelines)

 

3) i tried invoking events using eventinjector , but no luck again :smileysad:,  here i might be invoking wrong event. could you please tell me exact event to be invoked  in keychar method when enter is pressed (like

EventInjector.NavigationEvent.NAVIGATION_CLICK)

 

Thanks in advance again.

 

 

 

 

Please use plain text.
Developer
rabiray
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
My Carrier: Vodafone

Re: open objectChoiceField on press of enter , curve 8520 (JDE 5.0)

I have created  this sample...try this it works on press of enter key

 

public class HelloWorldScreen extends MainScreen {

ObjectChoiceField objectChoiceField;

public HelloWorldScreen()
{
setTitle("Test Screen");

objectChoiceField = new ObjectChoiceField("Test", new String []{"1","2","3"});
add(objectChoiceField);


}

protected boolean keyChar(char c, int status, int time) {

if(getFieldWithFocus() == objectChoiceField && c==Characters.ENTER){
EventInjector.invokeEvent(new EventInjector.NavigationEvent(EventInjector.NavigationEvent.NAVIGATION_UNCLICK, 0, 0, status

));
}
return true;
}

}

Please use plain text.
Developer
peter_strange
Posts: 19,598
Registered: ‎07-14-2008
My Device: Not Specified

Re: open objectChoiceField on press of enter , curve 8520 (JDE 5.0)

Just remembered how I had done this in the past:

 

 

    static String [] NUMBERS = new String [] { "1", "2", "3", "4", "5" };
    ObjectChoiceField _numberChoice = new ObjectChoiceField(null, NUMBERS, 0, ObjectChoiceField.FIELD_HCENTER) {
        protected void layout (int width, int height) {
            super.layout(this.getFont().getAdvance("9999"), height);
        }
        protected boolean keyChar(char c, int status, int time) {
            System.out.println("Char: " + c + ", status: " + status + " time: " + time);
            if ( c==Characters.ENTER ) {
                // this.navigationClick(status, time);
                ContextMenu cm = this.getContextMenu();
                MenuItem defaultmenu = cm.getDefaultItem();
                defaultmenu.run();
                return true;
            }
            return super.keyChar(c, status, time);
        }
    };

 

Please use plain text.