The Blackberry NullField

The Blackberry NullField

If you’ve ever perused the Blackberry Java documentation on a Friday evening (and who here hasn’t?), you may have come across the NullField.

NullField is a field that has no dimension, can’t be set in any meaningful way, and you can’t see it on the screen.

What the hell good is it for?

Well. This.

One of the annoying things you may have noticed when declaring a long LabelField (say, longer than the height of the screen) followed by some element that can take the focus (a TextEditField or a ButtonField), the user doesn’t get a chance to see the top of the LabelField.

Worse, they can’t scroll up and see it.

Some people resolve this by making the LabelField a RichTextField (so that it can accept the focus and can scroll).

Ah. But this is what NullField was designed for.

So that you could stick a NullField at the very front of a screen that would never be able to get the focus, and start there with the focus.

NullField is not the perfect solution. For example, scrolling is not smooth from visible focusable elements to hidden focusable elements. But at least you can set focus at the beginning (or the end) of long screens that otherwise have no elements that can be focused.

I can’t really understand why one can’t simply scroll all of a screen that is painted, regardless of whether the elements can have focus.

I know, right?

You just can’t.

So just use NullField and stop griping about the Blackberry SDK. Again.

Advertisements

One thought on “The Blackberry NullField

  1. Very good article about how to take advantage of a NullField. I also like your sense of humor.

    I was in the middle of a dilemma (see code below) while looking for a better alternative to set the default focus in a screen with multiple focusable elements, where at the same time I didn’t wanted to set the focus on any of them but an invisible one… and, voila!, there it is, in under a minute.

    _buttonSet.add( new NullField() );
    _buttonSet.add( loginBtn );
    _buttonSet.add( newAccountBtn );
    _vfm.add( _buttonSet );

    add( _vfm );
    try {
    //( (HorizontalFieldManager) profileslist.getField( 0 ) ).getField( 1 ).setFocus();
    _buttonSet.setFocus();
    }
    catch ( Exception e ) {
    //could’t assign focus
    focusTopField();
    }

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s