0

我想添加一个处理程序,该处理程序在 gwt 切换按钮显示向下面时继续执行。我正在尝试 keydown 但这不起作用。切换按钮中是否有任何方法允许这样做?

4

1 回答 1

0

Use a Timer:

ToggleButton myToggle = new ToggleButton();

Timer myTimer = new Timer() {
  @Override
  public void run() {
    if (myToggle.isDown()) {
      // Perform repeating action.
    } else {
      cancel();
    }
  }
};

myToggle.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
  @Override
  public void onValueChange(ValueChangeEvent<Boolean> event) {
    if (event.getValue().booleanValue() == true) {
      // Perform the repeating action twice/second.
      myTimer.scheduleRepeating(500);
    }
  }
});
于 2011-01-20T19:23:54.463 回答