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 ...

Get BlackBerry Java Application Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.