Code Explained

This code is similar to our previous example with the following differences:

■ In our UserlnterfaceScreen class, we declare that we implement FieldChangeListener interface. The method from this interface that we will define is "public void fieldChanged(Field field, int context)", described in the following section.

■ We declare instance variables for our greetingLabel and our userNameField as LabelField and BasicEditField, respectively. BasicEditField allows us to set a label and initial value for the text field.

■ We add these elements to the screen in our constructor.

■ We also create a ButtonField with the label "Hello BlackBerry!". We call setChangeListener(this) on this button to tell it to refer to the UserlnterfaceScreen object (this) when the button is clicked. The fieldChanged method will be called. This is why we implemented FieldChangeListener.

■ In fieldChanged, we set the value of the greetingLabel to "Hello" plus the current value of the userNameField.

Was this article helpful?

0 0
Living With Android

Living With Android

Get All The Support And Guidance You Need To Finally Be A Success At Using Android. This Book Is One Of The Most Valuable Resources In The World When It Comes To Playing With the Hottest Android Tablet.

Get My Free Ebook

Post a comment