O'Reilly logo

BlackBerry Java Application Development by Bill Foust

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - creating a ButtonField

  1. Start by adding the following code to the getValue method.
    if (f instanceof ButtonField)
    {
    Dialog.alert("HelloWorld!");
    }
    
  2. Next, add the following code to the createFields method.
    ButtonField button = new ButtonField("Button");
    button.setChangeListener(new FieldChangeListener()
    {
    public void fieldChanged(Field field,int context)
    {
    getValue();
    }
    });
    add(button);
    ButtonField button2 = new ButtonField("Button2", ButtonField.CONSUME_CLICK);
    button2.setChangeListener(this);
    add(button2);
    // A separator field between each type of control
    add(new SeparatorField());
    
  3. Replace the class declaration with the following one.
    public class FieldSamplerScreen extends MainScreen implements FieldChangeListener
    
  4. Add the following ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required