Tuesday, May 24, 2011

Moving to a New Screen with pushScreen

You can move to a new screen really easily but pushScreen. Create a new .java file named Question1.java. This will be our new screen. The basic new screen class is below, fill in the class name and constructor to the name of you java file.
/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class Question1 extends MainScreen
{
    /**
     * Creates a new Question1 object
     */
    public Question1()
    {       
        // Set the displayed title of the screen      
        setTitle("Question 1");
    }
}
So now, we can add a button, and make the button listener move to the new screen. This code should be in the "MyScreen" (your main screen) java file.

ButtonField btnNext = new ButtonField("Next question (2)", ButtonField.CONSUME_CLICK);
        FieldChangeListener customListener = new FieldChangeListener() {  
            public void fieldChanged(Field field, int context)
            {               
                UiApplication.getUiApplication().pushScreen(new Question1());
            }  
        };  
        btnNext.setChangeListener(customListener);
        this.add(btnNext);

Saturday, May 14, 2011

Blackberry RadioButtonField Example

How to use Blackberry RadioButtonField.



 //create a new set of radio buttons in a group
 RadioButtonGroup rgrp = new RadioButtonGroup();

 //new radio to the group
 RadioButtonField radio = new RadioButtonField("Radio Button 1", rgrp, true);
 add(radio);

 //another radio to the group
 RadioButtonField radio2 = new RadioButtonField("Radio Button 2", rgrp, false);
 add(radio2);

Download Project Source

Blackberry BitmapField Example

How to use Blackberry BitmapField.



 //create a new BitmapField
 Bitmap bm = Bitmap.getBitmapResource("images/test.png");
 BitmapField bf = new BitmapField(bm, BitmapField.FOCUSABLE);
 add(bf);

You can add images to development folder where the source files are.

Download Project Source

Blackberry PasswordEditField Example

How to use Blackberry PasswordEditField.



 //create a new PasswordEditField
 PasswordEditField pwf = new PasswordEditField();
 add(pwf);

 //create a new PasswordEditField with label and initial value
 PasswordEditField pwf2 = new PasswordEditField("Password: ", "mypassword");
 add(pwf2);

Download Project Source

Blackberry EditField Example

How to use Blackberry EditField.



 //create a new editfield
 EditField ef = new EditField();
 add(ef);

 //create a new editfield with default text and label
 EditField ef2 = new EditField("Message:", "Hello World!");
 add(ef2);

Download Project Source

Blackberry RichTextField Example

How to use Blackberry RichTextField.



 //create a new RichTextField
 RichTextField rtf = new RichTextField();
 add(rtf);

 //create a new RichTextField with a style, in this case "non focusable"
 RichTextField rtf2 = new RichTextField(NON_FOCUSABLE);
 add(rtf2);

 //create a new RichTextField with default text
 RichTextField rtf3 = new RichTextField("Hello World!");
 add(rtf3);

Download Project Source

Blackberry LabelField Example

How to use Blackberry LabelField.

 //new labelfield with no default text
 LabelField lf = new LabelField();
 lf.setText("Hello World!");
 add(lf);

 //new labelfield with default text
 LabelField lf2 = new LabelField("Hello World!");
 add(lf2);

Download Project Source