fieldChangeNotify is a method of the Field class.
this method is called by the framework for the Field when a change event occurs. you can also call this method when you know Field’s state is changed. When you call fieldChangeNotify you can pass a context as a information that can be used by the FieldChangeListener to identify and FieldChangeListener can use that information to identify the origin of the change.
Custom fieldChangeNotify
class MyScreen extends MainScreen implements FieldChangeListener {
private final static int ENTER_KEY = 101;
private final static int NAVIGATION_CLICK = 102;
MyScreen() {
LabelField clickableLabelField = new LabelField("Clickable Label",
Field.FOCUSABLE) {
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(NAVIGATION_CLICK);
return true;
}
protected boolean keyChar(char character, int status, int time) {
if (character == Characters.ENTER) {
fieldChangeNotify(ENTER_KEY);
return true;
}
return super.keyChar(character, status, time);
}
};
clickableLabelField.setChangeListener(this);
add(clickableLabelField);
}
public void fieldChanged(Field field, int context) {
if (context == ENTER_KEY)Status.show("You pressed the enter key");
if (context == NAVIGATION_CLICK)Status.show("You clicked on the field");
}
}
FieldChangeNotify invoked by the framework:
class MyScreen extends MainScreen implements FieldChangeListener {
BasicEditField textField;
MyScreen() {
textField = new BasicEditField("Text:(100) ","",100,BasicEditField.NO_NEWLINE);
textField.setChangeListener(this);
add(textField);
}
public void fieldChanged(Field field, int context) {
if(context != PROGRAMMATIC){
int textLength = textField.getMaxSize() - textField.getText().length();
textField.setLabel("Text:( "+ textLength+" ) ");
}
}
}
In previous example if you edit something, fieldchanged method will be invoked. In the fieldchanged method
we are changing label of BasicEditField. So this setLabel method will again invoke the fieldChanged method.
If we remove the if condition check, this program will through a stackoverflow exception.
So using context we can know the origin of event.
Incoming search terms:
- fieldchangenotify (10)
- blackberry labelfield fieldchangelistener (1)
- blackberry richtextfield fieldChanged (1)
- change position basiceditfield in blackberry (1)
- field change notify in blackberry (1)
- fieldchangenotify & navigationclick (1)
- fieldchangenotify blackberry (1)
- fieldchangenotify(0) (1)
- fieldchchangenotify(1) method in blackberry (1)