Creating a Custom Screen

We're actually using three screens in our UI Fun application already. Two are obvious: UiFunMainScreen and the login success screen. The third is the dialog that appears when you try to log in without entering a username and password (see Figure 5-24).

Figure 5-24. The login dialog is a Screen too

A screen on the BlackBerry doesn't have to take up the entire display; other screens can be visible below it. All screens, however, do take over the user input. That is, any keypresses, trackball presses, or touch screen taps only go to whatever screen is currently active and on top of the display stack. The active screen is also the one that controls the menu.

All screens are derived from net.rim.device.api.ui.Screen. We'll illustrate the concepts by creating a custom dialog to replace the default one, if for no other reason than we want to use our own colors and font and replace the OK button with one of our custom button fields.

We'll name our new screen CustomDialog (you should be seeing a pattern in our names by now) and directly subclass Screen. There is a PopupScreen class in net.rim.device.api.ui.container, but it adds some things that we don't want, like a border. The basic code looks like this:

package com.beginningblackberry.uifun; import net.rim.device.api.ui.Screen;

import net.rim.device.api.ui.container.VerticalFieldManager;

public class CustomDialog extends Screen { public CustomDialog(String message) { super(new VerticalFieldManager());

protected void sublayout(int width, int height) { }

Right away, you should notice two things. First, we're required to implement sublayout; this will actually be much easier than with a manager. Second, we're required to pass a Manager to Screen's constructor. This is the delegate manager.

0 0

Post a comment

  • Receive news updates via email from this site