質問

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.

役に立ちましたか?

解決

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().

他のヒント

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();
        }
     }
   }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top