Frage

I have five EditField objects in my BlackBerry app, each one will accept only one numeric character.

I want to change the focus from the first EditField to the second EditField when a character is entered. Note the focus from one to another EditField must go automatically and not by pressing Enter key or some other key.

War es hilfreich?

Lösung

You want to set a FieldChangeListener on the EditField to monitor when the contents of the field changes. Once the user has entered a single character you can move to the next field by calling Field.setFocus().

Andere Tipps

Lets assume your EditFields are added to screen one by one.

You could use next code:

editField<i>.setFieldChangeListener(this);
...
public void fieldChanged(Field field, int status) {
   if (field instanceof EditField) {
     EditField editField = (EditField)field;
     if (field.getText().length() > 0) {//don't move focus in case of deleted text
        Manager manager = field.getManager();
        Field nextField = manager.getField(manager.getFieldIndex(editField) + 1);
        if (nextField instanceof EditField) {
           nextField.setFocus();
        }
     }
   }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top