Book Image

BlackBerry Java Application Development

Book Image

BlackBerry Java Application Development

Overview of this book

BlackBerry Smartphone was once the domain of jet-setting business users with power suits. Now you can hardly go anywhere without seeing someone using a BlackBerry to check their messages or make a call. It's this kind of explosive growth that makes the BlackBerry ecosystem a great place to develop and market applications through the BlackBerry App World store—this book shows you how to do just that! This step-by-step guide gives you a hands-on experience of developing innovative Java applications for your BlackBerry. With the help of this book, you will learn to build your own applications to illustrate the platform, and the various capabilities that developers can use in their programs. It explores the powers of Blackberry and helps you develop professional and impressive Java applications. The book teaches how to write rich, interactive, and smart BlackBerry applications in Java. It expects the readers to know Java but not Java Mobile or the BlackBerry APIs. We will learn to build rich, interactive, and smart Java applications for the BlackBerry. The book will cover UI programming, data storage, programming network, and internet API apps. As we move on, we will learn more about the BlackBerry's device features, such as messaging, GPS, multimedia, contacts and calendar, and so on.This book also helps you build your own applications to illustrate the platform, and the various capabilities that developers can use in their programs.
Table of Contents (18 chapters)
BlackBerry Java Application Development
Credits
About the Author
Acknowledgement
About the Reviewers
Preface

Time for action - creating an ObjectChoiceField


  1. 1. Add the following code snippet to the createFields method in the FieldSampler project.

    String[] choices = {"Choice1","Choice2","Choice3"};
    //create an ObjectChoice
    ObjectChoiceField objChoice = new ObjectChoiceField( "Object Choice Field", choices);
    add(objChoice);
    // Another way to create the same ChoiceField.
    ObjectChoiceField objChoice2 = new ObjectChoiceField();
    objChoice2.setLabel("Another way");
    objChoice2.setChoices(choices);
    add(objChoice2);
    // A separator field between each type of control
    add(new SeparatorField());
    
  2. 2. Then add the following code to the getValue method.

    if (f instanceof ObjectChoiceField)
    {
    ObjectChoiceField choice = (ObjectChoiceField) f;
    int index = choice.getSelectedIndex();
    Object o = choice.getChoice(index);
    String s = (String) o;
    Dialog.alert("The selected value is " + s);
    }
    
  3. 3. Lastly, compile and run the application.

What just happened?

In this example, we demonstrated creating ChoiceFields in two different ways...